Previous Topic: OpenFile - Open a FileNext Topic: ReadFile - Read Data from a File


OpenPipe - Open 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 OpenPipe function opens a named pipe for reading or writing a client role.

Function format:

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

Specifies the name of the pipe to be opened.

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.

You can use the returned file handle with the functions ReadFile, WriteFile, and CloseFile. OpenPipe is used in the process that acts as a pipe client. Before you call OpenPipe, call the CreatePipe.

The pipe works in blocking mode. The read or write functions following OpenPipe wait until the server uses the inverse function.

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 shows a named pipe client.

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

pnam0 = argv(1)
pnam1 = argv(2)
stopstring = "---END---"

h0 = OpenPipe(pnam0, O_READ)	  
h1 = OpenPipe(pnam1, O_WRITE)	  
if h0 < 0 or h1	< 0 then
    print "open pipe failure. h0: " + str(h0) + "  h1: " + str(h1)
    print "pnam0: " + pnam0 + "  pnam1: " + pnam1
	exit
end if 

rc = ReadFile(h0, s)
print "read command rc: " + str(rc) + " " + s
if rc then
	for i = 1 to 5
		s1 = "RSP " + s + " line " + str(i) 
		rc = WriteFile(h1, s1)
		if not(rc) then
			print "write failed: " + s1
			exit for
		end if
	next i
	if rc then
		rc = WriteFile(h1, stopstring)
		if rc then
		    print "test successful"
		end if 
	end if
end if

CloseFile(h0)
CloseFile(h1)