Gambas文档
编译和安装
错误消息
代码片段
待办事项
废弃的组件
教程
开发环境文档
开发者文档
名词解释
如何操作
说明
维基手册
维基搜索
维基许可协议
文档
应用程序仓库
语言概览
语言索引
#Else
#Endif
#If
+INF
-INF
Abs
Access
ACos
ACosh
Alloc
AND
AND IF
Ang
APPEND
AS
Asc
ASin
ASinh
Asl
Asr
ASSERT
ATan
ATan2
ATanh
Base$
Base64$
BChg
BClr
BEGINS
Bin$
Boolean@
BREAK
BSet
BTst
BYREF
Byte@
CASE
CATCH
CBool
Cbr
CByte
CDate
Ceil
CFloat
CHGRP
CHMOD
Choose
CHOWN
Chr$
CInt
CLASS
CLong
CLOSE
Comp
CONST
CONTINUE
Conv$
COPY
Cos
Cosh
CPointer
CREATE
CREATE PRIVATE
CREATE STATIC
CShort
CSingle
CStr
CString
CVariant
Date
Date@
DateAdd
DateDiff
Day
DConv$
DEBUG
DEC
Dec
DEFAULT
Deg
DFree
DIM
Dir
DIV
DO
DOWNTO
EACH
ELSE
END
ENDIF
ENDS
END SELECT
END STRUCT
END WITH
ENUM
Eof
ERROR
ERROR TO
Eval
Even
EVENT
EXEC
Exist
Exp
Exp2
Exp10
Expm
EXPORT
EXTERN
FALSE
FAST
FAST UNSAFE
FINALLY
Fix
Float@
Floor
FLUSH
FOR
FOR EACH
Format$
Frac
Free
FromBase
FromBase64$
FromUrl$
FUNCTION
GOSUB
GOTO
Hex$
Hour
Html$
Hyp
IF
IIf
IN
INC
INCLUDE or #INCLUDE
INHERITS
INPUT
INPUT FROM
InStr
Int
Int@
Integer@
IS
IsAlnum
IsAscii
IsBlank
IsBoolean
IsDate
IsDigit
IsDir
IsFloat
IsHexa
IsInf
IsInteger
IsLCase
IsLetter
IsLong
IsLower
IsMissing
IsNaN
IsNull
IsNumber
IsPunct
IsSpace
IsUCase
IsUpper
KILL
LAST
LCase$
Left$
Len
LET
LIBRARY
LIKE
LINE INPUT
LINK
LOCK
Lof
Log
Log2
Log10
Logp
Long@
LOOP
Lsl
Lsr
LTrim$
Mag
MATCH
Max
ME
Mid$
Min
Minute
MkBool$
MkBoolean$
MkByte$
MkDate$
MKDIR
MkFloat$
MkInt$
MkInteger$
MkLong$
MkPointer$
MkShort$
MkSingle$
MOD
Month
MOVE
NEW
NEXT
NOT
Now
NULL
Oct$
Odd
ON GOSUB
ON GOTO
OPEN
OPEN MEMORY
OPEN MEMORY
OPEN NULL
OPEN PIPE
OPEN PIPE
OPEN STRING
OPTIONAL
OR
OR IF
OUTPUT
OUTPUT TO
PEEK
Pi
Pointer@
PRINT
PRIVATE
PROCEDURE
PROPERTY
PUBLIC
QUIT
Quote$
Rad
RAISE
Rand
RANDOMIZE
RDir
READ
Realloc
REPEAT
Replace$
RETURN
Right$
RInStr
RMDIR
Rnd
Rol
Ror
Round
RTrim$
Scan
SConv$
Second
SEEK
Seek
SELECT
Sgn
SHELL
Shell$
Shl
Short@
Shr
Sin
Single@
Sinh
SizeOf
SLEEP
Space$
Split
Sqr
Stat
STATIC
STEP
STOP
STOP EVENT
Str$
Str@
String$
String@
StrPtr
STRUCT
SUB
Subst$
SUPER
SWAP
Tan
Tanh
Temp$
THEN
Time
Timer
TO
Tr$
Trim$
TRUE
TRY
TypeOf
UCase$
UnBase64$
UNLOCK
Unquote$
UNTIL
Url$
USE
Val
VarPtr
WAIT
WATCH
Week
WeekDay
WEND
WHILE
WITH
WRITE
XOR
Year
本地化和翻译函数
变量声明
常量表达式
常量声明
方法声明
复数
赋值
赋值操作
行标号
结构体声明
局部变量声明
逻辑运算
枚举声明
内置集合
内置数组
使用保留字作为标识符
事件声明
事件循环
属性声明
数据类型
数据类型的二进制表示形式
数组声明
算术运算
外部函数管理
外部函数声明
语言常量
运算符优先级
专用方法
字符串操作
主题
组件
最近的修改

OPEN PIPE

Stream = [ OPEN ] PIPE PipeName FOR [ READ ] [ WRITE ] [ WATCH ]

打开一个命名的管道以便只读、只写或读写。如果管道不存在时,会被自动创建。

管道在同一系统的进程之间提供单向传送的通讯。换句话说,管道是半双工的,就是数据仅仅向一个方向传送。

管道的一个主要特征就是通过通讯媒介传送的数据是暂存数据,只能从读描述符读取一次。 同样,如果写连续数据到写描述符,则只能按照数据写入的顺序读取数据。

然而,在对管道进行读取或写入操作之前要两端同时打开。 为了读取合法的数据块,管道保持打开状态,直到其他的进程为了写入而打开这个管道。

自从 3.5

As of Gambas 3.15 pipes DO NOT block when opening.
(See hint at base of page about backward compatibility and for a workaround for blocking on previous gambas versions)

Gambas实现FIFO(先进先出)管道。更多的信息请看Linux/Unix手册中的MKFIFO部分。

  • 指定 READ 关键字,为读取打开管道。

  • 指定 WRITE 关键字,为写入打开管道。

  • 指定 WATCH 关键字,解释器将监视管道。
    • 如果从管道中读取至少一个字节,那么 File_Read() 事件处理会被调用。

    • 如果向管道中写入至少一个字节,那么 File_Write() 事件处理会被调用。

如果管道被成功打开,一个流对象被返回到 hStream 变量。

Pipe streams are never buffered.

自从 3.5

The OPEN PIPE syntax is available since Gambas 3.5.

If no process opens the pipe for writing, then any program using GTK+ and watching the pipe for reading will start to busy loop, eating 100% CPU.

This is a GTK+ feature.

The only workaround is opening the pipe both for reading and writing in the process that maintains it, so that there is always at least one writer.

自从 3.17

Since Gambas 3.17, pipes are always internally open for writing to workaround the problem. Beware that you still can write on the pipe only if you explicitly specify the WRITE flag.

Errors

Message Description
禁止访问(43) 不允许对管道的访问请求,或者路径中的某个目录的路径检索许可被拒绝,或者不允许对其父目录写访问。
设备已满(37) File name was to be created but the device containing Pipe name has no room for the new file.
非目录(49) A component used as a directory in Pipe name is not, in fact, a directory.
系统错误... (42) 其它可能的系统错误:
  • 解析路径时遇到太多的符号连接。

  • 路径参数超过最大路径长度,或者路径的某个目录超过目录名称最大长度。

  • 路径不能命名一个存在的目录,或者路径不能是空字符串。

  • 容纳新文件的目录不能扩展,或者文件系统缺乏文件分配资源。

  • 达到系统打开文件总数限制。

  • Pipe name 指向只读文件系统上的文件,并且有写访问请求。

Examples

' Prints the messages sent to a pipe
' Start that running in one window then do : ls > /tmp/FIFO1

Dim hFile AS File
Dim sLine AS String

hFile = Pipe "/tmp/FIFO1" For Read

Do
  Read #hFile, sLine, -256
  If Not sLine Then Break
  Print sLine;
Loop

' Another way of reading a pipe if you know that the data is a bunch of text lines

Dim hFile As File
Dim sLine As String

hFile = Pipe "/tmp/FIFO1" For Read

Do
  Line Input #hFile, sLine
  If hFile.EndOfFile Then Break
  Print sLine
Loop

See also

Hint:
In versions of Gambas below V 3.15 opening the pipe even for Watch would use the Linux default behaviour of locking your program until the pipe received some text.
A simple fix for this was to 'echo' something to the pipe using the Shell command just before opening like this...

 Shell "echo '' >/tmp/fifo1"
 hFile = Pipe "/tmp/fifo1" For Watch

Then opening the pipe would instantly receive some text and your program would continue to run.

As from Gambas V3.15+ Opening a pipe no longer locks the program waiting for text to be received as this behaviour was not considered useful.

So using the echo command is no longer needed but for backward compatibility (If your app is intended for others) it is advisable to still use it as your program will work okay on Gambas V3.15 without it but will lock on a lesser version runtime.