.TH "PipeStream" 3 "Mon Jan 12 2015" "Version dvi2bitmap1.0" "dvi2bitmap" \" -*- nroff -*- .ad l .nh .SH NAME PipeStream \- .PP Runs an external program, and provides access to the result\&. .SH SYNOPSIS .br .PP .PP \fC#include \fP .PP Inherits \fBInputByteStream\fP\&. .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBPipeStream\fP (string cmd, string envs='') throw (InputByteStreamError)" .br .RI "\fICreates a stream which returns the output of a given command\&. \fP" .ti -1c .RI "\fB~PipeStream\fP ()" .br .ti -1c .RI "string \fBgetResult\fP (bool allOfFile=false, bool gobbleRest=true) throw (InputByteStreamError)" .br .RI "\fIReturns the contents of the stream as a string\&. \fP" .ti -1c .RI "virtual void \fBclose\fP (void)" .br .RI "\fICloses the stream, and reaps the process status\&. \fP" .ti -1c .RI "int \fBgetTerminationStatus\fP (void)" .br .RI "\fIReturns the exit status of the command at the end of the pipe\&. \fP" .ti -1c .RI "pid_t \fBgetPid\fP (void) const " .br .RI "\fIReturns the PID of the running process\&. \fP" .in -1c .SS "Additional Inherited Members" .SH "Detailed Description" .PP Runs an external program, and provides access to the result\&. 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 \fBInputByteStream\fP, plus an additional one which retrieves the entire result as a string\&. .SH "Constructor & Destructor Documentation" .PP .SS "PipeStream::PipeStream (stringcmd, stringenvs = \fC''\fP)\fBInputByteStreamError\fP" .PP 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\&. .PP If the second argument is omitted, then a default list of environment variables, namely \fCPATH HOME LOGNAME SHELL TMPDIR\fP, are inherited from the current environment\&. If present, it should be a space-separated list of environment variables with optional values: if no equal sign is present, the variable's value is inherited from the current environment\&. For example, if this list is given as in the form \fCenv1=val1 env2= env3\fP, then \fCenv1\fP would receive the value \fCval1\fP, \fCenv2\fP would receive a null value, and \fCenv3\fP would be inherited\&. .PP If the command exits with a non-zero exit status, this is noted on \fCstderr\fP, but any output from the command is still returned\&. .PP If there's no way of doing this on a particular platform, throw \fC\fBInputByteStreamError\fP\fP always\&. .PP \fBParameters:\fP .RS 4 \fIcmd\fP the command to be run .br \fIenvs\fP if specified, this is a list of environment variables; if it is an empty string, \fC''\fP (the default), then a default list of variables is inherited .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP on any errors .RE .PP .PP References PipeStreamSignalHandling::expectAnother(), normal, NULL, Util::string_list_to_array(), and Util::tokenise_string()\&. .SS "PipeStream::~PipeStream ()" .SH "Member Function Documentation" .PP .SS "void PipeStream::close (void)\fC [virtual]\fP" .PP 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\&. .PP Reimplemented from \fBInputByteStream\fP\&. .PP References InputByteStream::close(), PipeStreamSignalHandling::got_status(), and normal\&. .SS "pid_t PipeStream::getPid (void) const\fC [inline]\fP" .PP Returns the PID of the running process\&. After the process has finished, this will return zero\&. .PP \fBReturns:\fP .RS 4 the process's PID, or zero if it has finished .RE .PP .SS "string PipeStream::getResult (boolallOfFile = \fCfalse\fP, boolgobbleRest = \fCtrue\fP)\fBInputByteStreamError\fP" .PP 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\&. .PP 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 \fCgetTerminationStatus\fP\&. .PP \fBParameters:\fP .RS 4 \fIallOfFile\fP if true, then all of the file is read into the string; if false (the default), only the first line is returned, \fInot\fP including the newline or carriage-return which ends the line .br \fIgobbleRest\fP if true (the default) then gobble the rest of the file; has an effect only if \fCallOfFile\fP was false .RE .PP \fBReturns:\fP .RS 4 the stream contents (or some of it, depending on the parameter values) as a string .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if there is some problem reading the stream .RE .PP .PP References normal, SS_STRING, and SSTREAM\&. .PP Referenced by PkFont::PkFont()\&. .SS "int PipeStream::getTerminationStatus (void)" .PP Returns the exit status of the command at the end of the pipe\&. Since this is only available after the process has completed, this invokes \fBclose\fP 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 \fCclose\fP is unable to terminate the process for some reason, this returns -1\&. .PP If the process exited normally, return the exit status of the command, as opposed to the raw exit status returned from the process, since this is more useful than the raw status with assorted other status information concerning anomalous exits\&. This status is non-negative\&. If the process did not exit normally, then return the negative of the raw status information, which we assert will be less than zero\&. .PP See waitpid(2) for details\&. .PP \fBReturns:\fP .RS 4 the exit status of the process\&. .RE .PP .PP Referenced by PkFont::PkFont()\&. .SH "Author" .PP Generated automatically by Doxygen for dvi2bitmap from the source code\&.