Process Class Reference

Execute a program and give access to its io An object of this class encapsulates the execution of an external program. It starts the program using fork and some exec.. call, gives you access to the program's stdio/stderr and closes the program after use. More...

#include <Process.h>

Inheritance diagram for Process:

ExternalProgram ExternalDataSource

List of all members.

Public Member Functions

 Process (const std::string &commandline, bool use_pty=false, bool default_locale=false)
 Process (const char *const *argv, const Environment &environment, bool use_pty=false, bool default_locale=false)
 ~Process ()
bool kill (int sig)
bool kill ()
std::string readLine ()
std::string read ()
std::string readErrLine ()
std::string readErr ()
int closeAll ()
void readStdoutToBuffer ()
void readStderrToBuffer ()
bool anyLineInStdout ()
FILE * errorFile ()

Private Member Functions

 Process (const Process &)
Processoperator= (const Process &)
int create_stderr_pipes ()
std::string GetLineFromBuffer (std::string &buffer)
void BufferNewStdoutLines ()
bool IsAnyLineInBuffer (const std::string &buffer)

Private Attributes

std::string stdout_buffer
std::string stderr_buffer
FILE * stderr_output


Detailed Description

Execute a program and give access to its io An object of this class encapsulates the execution of an external program. It starts the program using fork and some exec.. call, gives you access to the program's stdio/stderr and closes the program after use.

Constructor & Destructor Documentation

Process::Process ( const Process  )  [private]

Process::Process ( const std::string &  commandline,
bool  use_pty = false,
bool  default_locale = false 
) [inline]

Start the external program by using the shell /bin/sh with the option -c. You can use io direction symbols < and >.

Parameters:
commandline a shell commandline that is appended to /bin/sh -c.
default_locale whether to set LC_ALL=C before starting
use_pty start the process in a terminal

Process::Process ( const char *const *  argv,
const Environment environment,
bool  use_pty = false,
bool  default_locale = false 
) [inline]

Start an external program by giving the arguments as an arry of char *pointers. If environment is provided, variables will be added to the childs environment, overwriting existing ones.

Process::~Process (  ) 


Member Function Documentation

Process& Process::operator= ( const Process  )  [private]

int Process::create_stderr_pipes (  )  [private]

References stderr_output, and UnblockFD().

std::string Process::GetLineFromBuffer ( std::string &  buffer  )  [private]

Referenced by readErrLine(), and readLine().

void Process::BufferNewStdoutLines (  )  [private]

bool Process::IsAnyLineInBuffer ( const std::string &  buffer  )  [private]

Referenced by anyLineInStdout().

bool Process::kill ( int  sig  ) 

Send a signal

References ExternalProgram::getpid().

bool Process::kill (  ) 

Send SIGKILL

Reimplemented from ExternalProgram.

References ExternalProgram::kill().

Referenced by ~Process().

std::string Process::readLine (  ) 

Read a line from stdout

References BufferNewStdoutLines(), GetLineFromBuffer(), and stdout_buffer.

std::string Process::read (  ) 

Read characters from stdout (not line oriented)

References readStdoutToBuffer(), and stdout_buffer.

Referenced by main(), and readStdoutToBuffer().

std::string Process::readErrLine (  ) 

Read a line from stderr

References GetLineFromBuffer(), readStderrToBuffer(), and stderr_buffer.

std::string Process::readErr (  ) 

Read characters from stderr (not line oriented)

References readStderrToBuffer(), and stderr_buffer.

Referenced by main().

int Process::closeAll (  ) 

Close all input/output filedescriptors

References ExternalProgram::close(), and stderr_output.

void Process::readStdoutToBuffer (  ) 

Read stdout to the internal buffer (can unblock the process)

References b_size(), read(), ExternalDataSource::receive(), and stdout_buffer.

Referenced by read().

void Process::readStderrToBuffer (  ) 

Read stderr to the internal buffer (can unblock the process)

References b_size(), ERR, stderr_buffer, and stderr_output.

Referenced by readErr(), and readErrLine().

bool Process::anyLineInStdout (  ) 

Read whether there are some buffered lines

References BufferNewStdoutLines(), IsAnyLineInBuffer(), and stdout_buffer.

FILE * Process::errorFile (  ) 

Return the stderror stream

References stderr_output.

Referenced by main().


Member Data Documentation

std::string Process::stdout_buffer [private]

std::string Process::stderr_buffer [private]

FILE* Process::stderr_output [private]


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

Generated on Wed Dec 3 07:24:55 2008 for yast2-core by  doxygen 1.5.6