Previous Topic: CloseFile - Close the FileNext Topic: CreateFile - Create a New File


CreatePipe - Create a Pipe

Valid on UNIX and Windows

Note: This function is new in CA Client Automation and does not work with older versions of the Script Interpreter.

The CreatePipe function creates a named pipe for reading or writing in server role.

Function format:

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

Specifies the name of the pipe to be created. On UNIX, pipename is a valid pathname.

On Windows it has the form:

\\.\pipe\xxx

where xxx can contain any characters except '\'.

access

Specifies in what direction the pipe is used.

O_READ

(value 0) Opened for reading.

O_WRITE

(value 1) Opened for writing.

The function returns a file handle that you can use with functions ReadFile, WriteFile, and CloseFile.

CreatePipe is used in the process that acts as a pipe server. A pipe client uses the OpenPipe function.

The pipe works in blocking mode. The read or write functions following CreatePipe wait until a client uses the inverse function.

Note: The function is not available on Windows 95/98/ME.

On successful completion, the function returns a non-negative integer, which is the file handle. If the function fails, it returns -1.

Example:

This example assumes that the example of OpenPipe is stored as file 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)