AXCEL C++ Framework
Elegance through abstraction
Public Member Functions | Public Attributes
axcel::proc::pstream Class Reference

Pipe stdin and stdout of a process. More...

#include <axcel.h>

Inheritance diagram for axcel::proc::pstream:
axcel::io::ios axcel::io::input axcel::io::output axcel::io::iob axcel::io::iob axcel::object axcel::object

List of all members.

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?

Detailed Description

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.

Definition at line 2146 of file axcel.h.


Constructor & Destructor Documentation

axcel::proc::pstream::pstream ( )

Definition at line 6854 of file axcel.cpp.


Member Function Documentation

void axcel::proc::pstream::close ( )

Close redirected streams.

Closes the redirected stdin and stdout of the program started with the start() method from this object.

Definition at line 6804 of file axcel.cpp.

int axcel::proc::pstream::getc ( ) [virtual]

Read byte.

Returns:
Character read as an unsigned char cast to an int or EOF on end of file or error

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:

  • If end of file is reached, the method must call drain()
  • If a small error occurs but the stream is still usable, the method must call hurt()
  • If a fatal error occurs and the stream is unusable, the method must call kill()
  • If successful, the method must call heal()

Implements axcel::io::input.

Definition at line 6818 of file axcel.cpp.

string axcel::proc::pstream::name ( )

Get process name.

Definition at line 6777 of file axcel.cpp.

bool axcel::proc::pstream::open ( const char *  program,
const char *  argv,
data  envp 
)

Definition at line 6699 of file axcel.cpp.

bool axcel::proc::pstream::open ( const char *  program,
const char *  argv = 0,
void *  envp = 0 
)

Execute program.

Parameters:
programfilename of program to execute
argvCommand-line to pass to program
envpEnvironment block
Returns:
true on success, false on failure

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.

Definition at line 6703 of file axcel.cpp.

bool axcel::proc::pstream::open ( const char *  program,
const char *  argv,
environment  envp 
)

Definition at line 6695 of file axcel.cpp.

axcel::proc::pstream::operator size_t ( ) [inline]

Definition at line 2218 of file axcel.h.

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.

Definition at line 6873 of file axcel.cpp.

size_t axcel::proc::pstream::pid ( )

Get pid.

Returns:
Process ID of the program started from the start() method of this object

Definition at line 6817 of file axcel.cpp.

int axcel::proc::pstream::putc ( int  c) [virtual]

Write byte.

Parameters:
cCharacter to write
Returns:
Character written or EOF on end of file or error

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:

  • If end of file is reached, the method must call drain()
  • If an error occurs, the method must call kill()
  • If successful, the method must call heal()

Implements axcel::io::output.

Definition at line 6856 of file axcel.cpp.

string axcel::proc::pstream::type ( ) [virtual]

"proc::pstream"

Reimplemented from axcel::io::ios.

Definition at line 6872 of file axcel.cpp.


Member Data Documentation

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.

Definition at line 2164 of file axcel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines