#include <PipeStream.h>
Inheritance diagram for PipeStream:
Public Member Functions | |
PipeStream (string cmd, string envs="") throw (InputByteStreamError) | |
Creates a stream which returns the output of a given command. | |
~PipeStream () | |
string | getResult (bool allOfFile=false, bool gobbleRest=true) throw (InputByteStreamError) |
Returns the contents of the stream as a string. | |
virtual void | close (void) |
Closes the stream, and reaps the process status. | |
int | getTerminationStatus (void) |
Returns the status of the command at the end of the pipe. | |
pid_t | getPid (void) const |
Returns the PID of the running process. |
This runs a given command in a forked process, optionally adjusting the environment as it does so. The output from the command is available using the methods of an InputByteStream, plus an additional one which retrieves the entire result as a string.
|
Creates a stream which returns the output of a given command. The constructor open a pipe with the given command, and prepares for the results to be read by this class's accessor methods.
If the second argument is omitted, then a default list of environment variables, namely
If the command exits with a non-zero exit status, this is noted on
If there's no way of doing this on a particular platform, throw
|
|
|
|
Closes the stream, and reaps the process status. If the process has not already terminated, this method attempts to kill it, by sending first HUP then KILL. If there is some reason why we can't reap the status -- because it has not died or for, say, some permissions reason -- we set the returned status to -1. Any data not read from the pipe is discarded. Reimplemented from InputByteStream.
|
|
Returns the PID of the running process. After the process has finished, this will return zero.
|
|
Returns the contents of the stream as a string. If some of the stream has already been read by other methods of this class or its parent, it cannot be re-read. Any trailing whitespace, including end-of-line characters, is stripped.
It's possible that the returned string will be incomplete, if the process failed somehow; irrespective of whether this happened, this returns what it can, and if this condition matters to you, you should check the termination status with
|
|
Returns the status of the command at the end of the pipe.
Since this is only available after the process has completed, this invokes close on the stream first. Thus you should not invoke this method until after you have extracted all of the command's output that you want. If
|