YGP::Process Class Reference

Class to execute a program either synchronlously or asynchronlously. More...

List of all members.

Public Types

enum  {
  NO_WAIT = 0, WAIT = 1, CONNECT_STDOUT = 2, CONNECT_STDERR = 4,
  CONNECT_STDOUT_AND_ERR = 8
}

Static Public Member Functions

static pid_t execAsync (const char *file, const char *const arguments[]) throw (YGP::ExecError)
static void execute (const char *file, const char *const arguments[]) throw (YGP::ExecError)
static pid_t execIOConnected (const char *file, const char *const arguments[], int *fd, unsigned int flags=CONNECT_STDOUT_AND_ERR) throw (YGP::ExecError)
static pid_t getPID ()
static int waitForProcess (pid_t pid)

Static Protected Member Functions

static pid_t start (const char *file, const char *const arguments[], int flags, int *fd=NULL) throw (YGP::ExecError)


Detailed Description

Class to execute a program either synchronlously or asynchronlously.

The program is supposed to return 0, if it succeeds and any other value if it encounters an error. In case of an error it should display its error on stdout or stderr. This output is captured and thrown as exception for the caller.

In case of an asynchron running program it must display its error in (more or less) the first second of its execution (as the controlling process only waits one second before checking for program termination).

Note:
This class has only static members!

Member Function Documentation

static pid_t YGP::Process::execAsync ( const char *  file,
const char *const   arguments[] 
) throw (YGP::ExecError) [inline, static]

Executes a program asynchronously to the execution of the current process.

If either the file can not be found or produces an error while initializing (in the more or less 1st second) an describing text (at least if the program produces an helpful output) is thrown.

Parameters:
file Name of file to execute
arguments Array with arguments for the file (as understood by execv)
Returns:
pid_t PID of created process
Precondition:
file is a valid ASCIIZ-string
Exceptions:
YGP::ExecError An error-message displayed by the program
Remarks:
The called file must follow some convention:
  • Return 0 if OK and !0 if an error occured
  • In case of an error the output should contain a describing message

static pid_t YGP::Process::execIOConnected ( const char *  file,
const char *const   arguments[],
int *  fd,
unsigned int  flags = CONNECT_STDOUT_AND_ERR 
) throw (YGP::ExecError) [inline, static]

Executes a program in the background.

If either the file can not be found or produces an error while initializing (in the more or less 1st second) an describing text (at least if the program produces an helpful output) is thrown.

Parameters:
file Name of file to execute
arguments Array with arguments for the file (as understood by execv)
fd Pipes for communication
flags Flags describing how to connect stdin/stdout
Returns:
pid_t PID of created process
Precondition:
file is a valid ASCIIZ-string
Exceptions:
YGP::ExecError An error-message displayed by the program
Remarks:
The called file must follow some convention:
  • Return 0 if OK and !0 if an error occured
  • In case of an error the output should contain a describing message

static void YGP::Process::execute ( const char *  file,
const char *const   arguments[] 
) throw (YGP::ExecError) [inline, static]

Executes a program.

The execution of the calling process is suspended, til the new program has terminated. If either the file can not be found or produces an error while executing an describing text (at least if the program produces an helpful output) is thrown.

Parameters:
file Name of file to execute
arguments Array with arguments for the file (as understood by execv)
Precondition:
file is a valid ASCIIZ-string
Exceptions:
YGP::ExecError An error-message displayed by the program
Remarks:
The called file must follow some convention:
  • Return 0 if OK and !0 if an error occured
  • In case of an error the output should contain a describing message

static pid_t YGP::Process::getPID (  )  [inline, static]

Returns the process ID of the actual process.

Returns:
pid_t Process ID of running process

pid_t YGP::Process::start ( const char *  file,
const char *const   arguments[],
int  flags,
int *  fd = NULL 
) throw (YGP::ExecError) [static, protected]

Executes a program, either in the back- or foreground.

If either the file can not be found or produces an error while executing/initializing (in the more or less 1st second) an describing text (at least if the program produces an helpful output) is thrown.

Parameters:
file Name of file to execute
arguments Array with arguments for the file (as understood by execv)
flags Flags; e.g. if to wait til the program terminates
fd Filedescriptors for communication with the child.
  • fd[0] contains the filedescriptor the child should read its data from; will be overwritten with the descriptor the output from the child can be read from (if flags & CONNECT_STDOUT or flags & CONNECT_STDOUT_AND_ERR)
  • fd[1] is expected to contain the matching file descriptor for the pipe for the communication (which the child can close)
  • fd[2] will be filled with the descriptor from which the errors of the child can be read from (if flags & CONNECT_STDERR) filled with the filedescriptor for the output
Precondition:
file is a valid ASCIIZ-string
Returns:
pid_t PID of created process
Exceptions:
YGP::ExecError An error-message displayed by the program
Remarks:
The called file must follow some convention:
  • Return 0 if OK and !0 if an error occured
  • In case of an error the output should contain a describing message

int YGP::Process::waitForProcess ( pid_t  pid  )  [static]

Wait til process has terminated.

Parameters:
pid Proess to wait for
Returns:
int Returncode of the program


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

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:28 2009 by doxygen 1.5.8