AXCEL C++ Framework
Elegance through abstraction
|
Pipe stdin and stdout of a process. More...
#include <axcel.h>
Public Member Functions | |
pstream () | |
virtual string | type () |
"proc::pstream" | |
virtual | operator string () |
Get PID and name. | |
string | name () |
Get process name. | |
int | getc () |
Read byte. | |
int | putc (int c) |
Write byte. | |
bool | open (const char *program, const char *argv=0, void *envp=0) |
Execute program. | |
bool | open (const char *program, const char *argv, environment envp) |
bool | open (const char *program, const char *argv, data envp) |
void | close () |
Close redirected streams. | |
size_t | pid () |
Get pid. | |
operator size_t () | |
Public Attributes | |
bool | blocking |
Should data read block? |
Pipe stdin and stdout of a process.
Used for executing a program and reading from and writing to the child process's standard input and output streams.
void axcel::proc::pstream::close | ( | ) |
int axcel::proc::pstream::getc | ( | ) | [virtual] |
Read byte.
Reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. Before returning from the method, one of the following methods of the stream must be called:
Implements axcel::io::input.
bool axcel::proc::pstream::open | ( | const char * | program, |
const char * | argv, | ||
data | envp | ||
) |
bool axcel::proc::pstream::open | ( | const char * | program, |
const char * | argv = 0 , |
||
void * | envp = 0 |
||
) |
Execute program.
program | filename of program to execute |
argv | Command-line to pass to program |
envp | Environment block |
Forks and executes the program pointed to by program. program must be either a binary executable, or a sciprt starting with a line of the form:
#! interpreter [optional-arg]
See execve(2) Linux documentation for details.
envp should point to a null-terminated array of C-strings in the form "VAR=VALUE". argv should contain the arguments to pass to the program excluding the first argument (this method automatically passes the program name as the first argument). Once the program is running it's stdin and stdout streams will be available to this object to read from and write to.
bool axcel::proc::pstream::open | ( | const char * | program, |
const char * | argv, | ||
environment | envp | ||
) |
axcel::proc::pstream::operator string | ( | ) | [virtual] |
Get PID and name.
Returns a string in the form PID:NAME where PID is the process ID of the running process opened with open(), and name is the name of the opened program.
Reimplemented from axcel::io::ios.
size_t axcel::proc::pstream::pid | ( | ) |
int axcel::proc::pstream::putc | ( | int | c | ) | [virtual] |
Write byte.
c | Character to write |
Writes character c to stream and returns a non-negative number on success or EOF on error. Before returning from within this method, one of the following methods must be called:
Implements axcel::io::output.
string axcel::proc::pstream::type | ( | ) | [virtual] |
Should data read block?
If set to true (default), any methods which read from this stream will block until data becomes available to read. If set to false, data input methods will read nothing and set the stream status to eof. In either case, if the program has terminated and you try to read from it's output, the stream will have the dead indicator set and the method will fail.