adbncfs  0.9.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Spawn Class Reference

Spawn a child process. More...

#include <spawn.h>

Collaboration diagram for Spawn:
Collaboration graph
[legend]

Public Member Functions

 Spawn (const char *const argv[], bool fUseStdErr=false, bool fWithPath=false, const char *const envp[]=NULL)
 Spawns a child process. More...
 
virtual ~Spawn ()
 
std::istream & inStream ()
 Access the child process stdout as in stream to read from. More...
 
std::ostream & outStream ()
 Access the child process stdin as out stream to write to the process. More...
 
void sendEof ()
 
int wait ()
 Wait until child process has terminated. More...
 

Private Member Functions

 Spawn (const Spawn &orig)
 Prevent copy-construction. More...
 
Spawnoperator= (const Spawn &orig)
 Prevent assignment. More...
 

Private Attributes

int m_iChildPid
 
__gnu_cxx::stdio_filebuf< char > * m_pWriteBuf
 
__gnu_cxx::stdio_filebuf< char > * m_pReadBuf
 
std::ostream stdin
 
std::istream stdout
 
Cpipe m_WritePipe
 
Cpipe m_ReadPipe
 

Detailed Description

Spawn a child process.

Usage: spawn s(argv); s.outStream() << ... s.inStream() >> ... s.sendEof(); s.wait();

Definition at line 66 of file spawn.h.

Constructor & Destructor Documentation

Spawn::Spawn ( const char *const  argv[],
bool  fUseStdErr = false,
bool  fWithPath = false,
const char *const  envp[] = NULL 
)

Spawns a child process.

Parameters
argvan array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, must point to the filename associated with the file being executed. The array of pointers must be terminated by a NULL pointer.
fUseStdErrif true stderr is redirected instead of stdout.
fWithPathif true and argv[0] does not contain a slash (/) executable is sought in the PATH environment variable, otherwise PATH is ignored, and the file at the specified pathname is executed.
envpis an array of strings, conventionally of the form key=value, which are passed as environment to the new program. must be terminated by a NULL pointer.
Exceptions
runtime_errorif child process could not be started of if no pipe could be created.

Definition at line 87 of file spawn.cpp.

Here is the call graph for this function:

Spawn::~Spawn ( )
virtual

Definition at line 143 of file spawn.cpp.

Spawn::Spawn ( const Spawn orig)
private

Prevent copy-construction.

Member Function Documentation

std::istream& Spawn::inStream ( )
inline

Access the child process stdout as in stream to read from.

Returns
a istream to read the output of the child process.

Definition at line 77 of file spawn.h.

Here is the caller graph for this function:

Spawn& Spawn::operator= ( const Spawn orig)
private

Prevent assignment.

std::ostream& Spawn::outStream ( )
inline

Access the child process stdin as out stream to write to the process.

Returns
a ostream to write to the stdin of the child process.

Definition at line 84 of file spawn.h.

Here is the caller graph for this function:

void Spawn::sendEof ( )

Definition at line 152 of file spawn.cpp.

Here is the caller graph for this function:

int Spawn::wait ( )

Wait until child process has terminated.

The returned status can be inspected with the following macros:

  • WIFEXITED(status)
  • WEXITSTATUS(status)
  • WIFSIGNALED(status)
  • WTERMSIG(status)
  • WCOREDUMP(status)
Returns
the status of the terminated child process or EXIT_FAILURE if an error occurred.
See also
wait(2) - Linux manual page - man7.org

Definition at line 172 of file spawn.cpp.

Here is the caller graph for this function:

Member Data Documentation

int Spawn::m_iChildPid
private

Definition at line 95 of file spawn.h.

__gnu_cxx::stdio_filebuf<char>* Spawn::m_pReadBuf
private

Definition at line 97 of file spawn.h.

__gnu_cxx::stdio_filebuf<char>* Spawn::m_pWriteBuf
private

Definition at line 96 of file spawn.h.

Cpipe Spawn::m_ReadPipe
private

Definition at line 101 of file spawn.h.

Cpipe Spawn::m_WritePipe
private

Definition at line 100 of file spawn.h.

std::ostream Spawn::stdin
private

Definition at line 98 of file spawn.h.

std::istream Spawn::stdout
private

Definition at line 99 of file spawn.h.


The documentation for this class was generated from the following files: