class PPipeChannel

A channel that uses a operating system pipe between the current process and a sub-process.

Inheritance:


Public Methods

[more] Overrides from class PObject
[more] Overrides from class PChannel
[more] New member functions

Public Members

[more] Construction

Protected Fields

[more]PFilePath subProgName
The fully qualified path name for the sub-program executable


Inherited from PChannel:

Public Methods

Information functions

Reading functions

Writing functions

Miscellaneous functions

ostatic BOOL ConvertOSError( int libcReturnValue, Errors & lastError, int & osError )

Public Members

Error functions

Protected Fields

oint os_handle
oErrors lastErrorCode[NumErrorGroups+1]
oint lastErrorNumber[NumErrorGroups+1]
oPINDEX lastReadCount
oPINDEX lastWriteCount
oPTimeInterval readTimeout
oPTimeInterval writeTimeout

Protected Methods

ovirtual BOOL ConvertOSError( int libcReturnValue, ErrorGroup group = LastGeneralError )
oBOOL SetErrorValues( Errors errorCode, int osError, ErrorGroup group = LastGeneralError )
oint ReadCharWithTimeout( PTimeInterval & timeout )


Inherited from PObject:

Public Methods

Run Time Type functions

I/O functions

Public Members

Comparison functions


Documentation

A channel that uses a operating system pipe between the current process and a sub-process. On platforms that support multi-processing, the sub-program is executed concurrently with the calling process.

Where full multi-processing is not supported then the sub-program is run with its input supplied from, or output captured to, a disk file. The current process is then suspended during the execution of the sub-program. In the latter case the semantics of the Execute() and Close() functions change from the usual for channels.

Note that for platforms that do not support multi-processing, the current process is suspended until the sub-program terminates. The input and output of the sub-program is transferred via a temporary file. The exact moment of execution of the sub-program depends on the mode. If mode is ReadOnly then it is executed immediately and its output captured. In WriteOnly mode the sub-program is run when the Close() function is called, or when the pipe channel is destroyed. In ReadWrite mode the sub-program is run when the Execute() function is called indicating that the output from the current process to the sub-program has completed and input is now desired.

The CanReadAndWrite() function effectively determines whether full multi-processing is supported by the platform. Note that this is different to whether multi-threading is supported.

o Construction

oenum OpenMode
Channel mode for the pipe to the sub-process

o ReadOnly
Pipe is only from the sub-process to the current process

o WriteOnly
Pipe is only from the current process to the sub-process

o ReadWrite
Pipe is bidirectional between current and sub-processes

o ReadWriteStd
Pipe is bidirectional between current and sub-processes but the write side goes to stdout and stderr

o PPipeChannel()
Create a new pipe channel

o PPipeChannel( const PString & subProgram, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Create a new pipe channel. This executes the subProgram and transfers data from its stdin/stdout/stderr.

See the Open() function for details of various parameters.

Parameters:
subProgram - Sub program name or command line.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

o PPipeChannel( const PString & subProgram, const PStringArray & argumentList, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Create a new pipe channel. This executes the subProgram and transfers data from its stdin/stdout/stderr.

See the Open() function for details of various parameters.

Parameters:
subProgram - Sub program name or command line.
argumentList - Array of arguments to sub-program.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

o PPipeChannel( const PString & subProgram, const PStringToString & environment, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Create a new pipe channel. This executes the subProgram and transfers data from its stdin/stdout/stderr.

See the Open() function for details of various parameters.

Parameters:
subProgram - Sub program name or command line.
environment - Array of arguments to sub-program.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

o PPipeChannel( const PString & subProgram, const PStringArray & argumentList, const PStringToString & environment, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Create a new pipe channel. This executes the subProgram and transfers data from its stdin/stdout/stderr.

See the Open() function for details of various parameters.

Parameters:
subProgram - Sub program name or command line.
argumentList - Array of arguments to sub-program.
environment - Array of arguments to sub-program.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

o ~PPipeChannel()
Close the pipe channel, killing the sub-process

o Overrides from class PObject

oComparison Compare( const PObject & obj ) const
Determine if the two objects refer to the same pipe channel. This actually compares the sub-program names that are passed into the constructor.

Parameters:
obj - Another pipe channel to compare against.
Returns:
Comparison value of the sub-program strings.

o Overrides from class PChannel

ovirtual PString GetName() const
Get the name of the channel.

Returns:
string for the sub-program that is run.

ovirtual BOOL Read( void* buf, PINDEX len )
Low level read from the channel. This function may block until the requested number of characters were read or the read timeout was reached. The GetLastReadCount() function returns the actual number of bytes read.

If there are no more characters available as the sub-program has stopped then the number of characters available is returned. This is similar to end of file for the PFile channel.

The GetErrorCode() function should be consulted after Read() returns FALSE to determine what caused the failure.

Parameters:
buf - Pointer to a block of memory to receive the read bytes.
len - Maximum number of bytes to read into the buffer.
Returns:
TRUE indicates that at least one character was read from the channel. FALSE means no bytes were read due to timeout or some other I/O error.

ovirtual BOOL Write( const void* buf, PINDEX len )
Low level write to the channel. This function will block until the requested number of characters are written or the write timeout is reached. The GetLastWriteCount() function returns the actual number of bytes written.

If the sub-program has completed its run then this function will fail returning FALSE.

The GetErrorCode() function should be consulted after Write() returns FALSE to determine what caused the failure.

Parameters:
buf - Pointer to a block of memory to write.
len - Number of bytes to write.
Returns:
TRUE if at least len bytes were written to the channel.

ovirtual BOOL Close()
Close the channel. This will kill the sub-program's process (on platforms where that is relevent).

For WriteOnly or ReadWrite mode pipe channels on platforms that do no support concurrent multi-processing and have not yet called the Execute() function this will run the sub-program.

o New member functions

oBOOL Open( const PString & subProgram, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Open a channel.
Parameters:
subProgram - Sub program name or command line.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

oBOOL Open( const PString & subProgram, const PStringArray & argumentList, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Open a channel.
Parameters:
subProgram - Sub program name or command line.
argumentList - Array of arguments to sub-program.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

oBOOL Open( const PString & subProgram, const PStringToString & environment, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Open a channel.
Parameters:
subProgram - Sub program name or command line.
environment - Array of arguments to sub-program.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

oBOOL Open( const PString & subProgram, const PStringArray & argumentList, const PStringToString & environment, OpenMode mode = ReadWrite, BOOL searchPath = TRUE, BOOL stderrSeparate = FALSE )
Open a new pipe channel allowing the subProgram to be executed and data transferred from its stdin/stdout/stderr.

If the mode is ReadOnly then the stdout of the sub-program is supplied via the Read() calls of the PPipeChannel. The sub-programs input is set to the platforms null device (eg /dev/nul).

If mode is WriteOnly then Write() calls of the PPipeChannel are suppied to the sub-programs stdin and its stdout is sent to the null device.

If mode is ReadWrite then both read and write actions can occur.

The subProgram parameter may contain just the path of the program to be run or a program name and space separated arguments, similar to that provided to the platforms command processing shell. Which use of this parameter is determiend by whether arguments are passed via the argumentPointers or argumentList parameters.

The searchPath parameter indicates that the system PATH for executables should be searched for the sub-program. If FALSE then only the explicit or implicit path contained in the subProgram parameter is searched for the executable.

The stderrSeparate parameter indicates that the standard error stream is not included in line with the standard output stream. In this case, data in this stream must be read using the ReadStandardError() function.

The environment parameter is a null terminated sequence of null terminated strings of the form name=value. If NULL is passed then the same invironment as calling process uses is passed to the child process.

Parameters:
subProgram - Sub program name or command line.
argumentList - Array of arguments to sub-program.
environment - Array of arguments to sub-program.
mode - Mode for the pipe channel.
searchPath - Flag for system PATH to be searched.
stderrSeparate - Standard error is on separate pipe

oconst PFilePath& GetSubProgram() const
Get the full file path for the sub-programs executable file.

Returns:
file path name for sub-program.

oBOOL Execute()
Start execution of sub-program for platforms that do not support multi-processing, this will actually run the sub-program passing all data written to the PPipeChannel.

For platforms that do support concurrent multi-processing this will close the pipe from the current process to the sub-process.

As the sub-program is run immediately and concurrently, this will just give an end of file to the stdin of the remote process. This is often necessary.

Returns:
TRUE if execute was successful.

oBOOL IsRunning() const
Determine if the program associated with the PPipeChannel is still executing. This is useful for determining the status of PPipeChannels which take a long time to execute on operating systems which support concurrent multi-processing.

Returns:
TRUE if the program associated with the PPipeChannel is still running

oint GetReturnCode() const
Get the return code from the most recent Close;

Returns:
Return code from the closing process

oint WaitForTermination()
This function will block and wait for the sub-program to terminate.

Returns:
Return code from the closing process

oint WaitForTermination( const PTimeInterval & timeout )
This function will block and wait for the sub-program to terminate. It will wait only for the specified amount of time.

Parameters:
timeout - Amount of time to wait for process.
Returns:
Return code from the closing process, -1 if timed out.

oBOOL Kill( int signal = 9 )
This function will terminate the sub-program using the signal code specified.

Parameters:
signal - Signal code to be sent to process.
Returns:
TRUE if the process received the signal. Note that this does not mean that the process has actually terminated.

oBOOL ReadStandardError( PString & errors, BOOL wait = FALSE )
Read all available data on the standard error stream of the sub-process. If the wait parameter is FALSE then only the text currently available is returned. If TRUE then the function blocks as long as necessary to get some number of bytes.

Parameters:
errors - String to receive standard error text.
wait - Flag to indicate if function should block
Returns:
TRUE indicates that at least one character was read from stderr. FALSE means no bytes were read due to timeout or some other I/O error.

ostatic BOOL CanReadAndWrite()
Determine if the platform can support simultaneous read and writes from the PPipeChannel (eg MSDOS returns FALSE, Unix returns TRUE).

Returns:
TRUE if platform supports concurrent multi-processing.

oPFilePath subProgName
The fully qualified path name for the sub-program executable


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.