前のトピック: CloseFile - ファイルのクローズ次のトピック: CreateFile - 新規ファイルの作成


CreatePipe - パイプの作成

UNIX および Windows で有効です。

注: この関数は、CA Client Automation で新しく使用されるようになったため、古いバージョンのスクリプト インタープリタでは動作しません。

CreatePipe 関数は、サーバ役割内に読み書き用の名前付きパイプを作成します。

関数の形式

CreatePipe(pipename as String, access as Integer) as Integer
pipename

作成するパイプの名前を指定します。 UNIX では、pipename は有効なパス名です。

Windows では、以下の形式になります。

\\.\pipe\xxx

ここで、xxx には「\」を除く任意の文字を含めることができます。

access

パイプを使用する方向を指定します。

O_READ

(値 0)読み取りのために開きます。

O_WRITE

(値 1)書き込みのために開きます。

この関数は、関数 ReadFile、WriteFile、および CloseFile で使用できるファイル ハンドルを返します。

CreatePipe はパイプ サーバとして機能するプロセス内で使用します。 パイプ クライアントは OpenPipe 関数を使用します。

パイプは、ブロック モードで機能します。 CreatePipe の後に続く読み書き関数は、クライアントが反対の関数を使用するまで待機します。

注: この関数は Windows 95/98/ME では使用できません。

この関数が正常に完了すると、負でない整数(ファイル ハンドル)が返されます。 この関数が失敗すると、-1 が返されます。

例:

以下の例では、OpenPipe がファイル p0cl.dms として格納されると想定しています。

rem example named pipe server
rem create two pipes
rem start client process
rem write command to one pipe
rem read response from second pipe

dim rc, h0, h1 as integer
dim pnam0, pnam1 as string
dim stopstring as string
dim s, cmd as string
dim iswin as boolean

if left(osstring, 3) = "Win" then
    pnam0 = "\\.\pipe\p0rsp"
    pnam1 = "\\.\pipe\p0cmd"
	iswin = 1
else
    pnam0 = "/tmp/p0rsp"
    pnam1 = "/tmp/p0cmd"
	iswin = 0
endif
stopstring = "---END---"

h0 = CreatePipe(pnam0, O_READ)	  'read response form client
h1 = CreatePipe(pnam1, O_WRITE)	  'send command to client
if h0 < 0 or h1	< 0 then
    print "create pipe failure. h0: " + str(h0) + "  h1: " + str(h1)
	exit
end if 

if iswin then
	cmd = "dmscript p0cl.dms -o_dms: p0clout.txt -script "	+ pnam1 + " " + pnam0
	rc = Exec(cmd, 0) 
else
	cmd = "dmscript p0cl.dms -o_dms: p0clout.txt -script " + pnam1 + " " + pnam0 + " &"
	rc = Exec(cmd) 
end if
print "exec rc: " + str(rc) + " cmd: " + cmd

rc = WriteFile(h1, "command")
if not(rc) then
	print "write command failed"
else    
	while rc
		rc = ReadFile(h0, s)
		print "read response rc: " + str(rc) + " " + s
		if s = stopstring then
			rc = 0
			print "test successful"
		end if
	wend
end if

CloseFile(h0)
CloseFile(h1)