utilmm::process Class Reference
[OS-related tools]

#include <utilmm/system/process.hh>

List of all members.

Public Types

enum  Stream { Stdout = 1, Stderr = 2 }

Public Member Functions

 process ()
 ~process ()
void set_workdir (boost::filesystem::path const &dir)
boost::filesystem::path workdir () const
std::list< std::string > cmdline () const
void push (const std::string &arg)
processoperator<< (std::string const &newarg)
void clear ()
void start ()
void signal (int signo=SIGINT)
void wait ()
void detach ()
void erase_redirection (Stream stream)
void redirect_to (Stream stream, int handle, bool auto_close=true)
void redirect_to (Stream stream, FILE *handle, bool auto_close=true)
void redirect_to (Stream stream, boost::filesystem::path const &file)
void set_environment (const std::string &key, const std::string &value)
std::string environment (const std::string &key) const
void clear_environment ()
void set_pgid (pid_t pid)
bool exit_normal () const
int exit_status () const
pid_t pid () const
bool running ()

Static Public Member Functions

static void install_sigint_handler ()
static void killall ()

Static Public Attributes

static const int InvalidHandle = -1

Classes

class  already_running
struct  output_file


Detailed Description

An external process

Author:
Sylvain Joyeux <sylvain.joyeux@laas.fr>

Member Enumeration Documentation

enum utilmm::process::Stream

Definition of the streams we can redirect to

Enumerator:
Stdout 
Stderr 


Constructor & Destructor Documentation

utilmm::process::process (  ) 

utilmm::process::~process (  ) 


Member Function Documentation

void utilmm::process::set_workdir ( boost::filesystem::path const &  dir  ) 

Set the working directory

boost::filesystem::path utilmm::process::workdir (  )  const

Get the working directory

Returns:
the value set by set_workdir, or an empty string

std::list<std::string> utilmm::process::cmdline (  )  const

Get the list of elements in the command line. It includes the process name.

void utilmm::process::push ( const std::string &  arg  ) 

Add an element on the command line

process& utilmm::process::operator<< ( std::string const &  newarg  ) 

An alias to push

See also:
push

void utilmm::process::clear (  ) 

Clear the command line

void utilmm::process::start (  ) 

Start the process

Exceptions:
unix_error an error occured while starting the process
already_running this process object has already started

void utilmm::process::signal ( int  signo = SIGINT  ) 

Send a signal to a running process

static void utilmm::process::install_sigint_handler (  )  [static]

Install a SIGINT handler which calls process::killall

static void utilmm::process::killall (  )  [static]

Kill all processes managed by a process instance It is safe to call this inside a signal handler

void utilmm::process::wait (  ) 

Wait for the process to terminate Use running() to check if the process is running or not

void utilmm::process::detach (  ) 

Detach from a running process Call this to make the process object forget about a running child.

After a call to detach(), the child process won't be stopped when this object is destroyed

void utilmm::process::erase_redirection ( Stream  stream  ) 

Removes any redirection for stream

Parameters:
stream the output stream to consider

void utilmm::process::redirect_to ( Stream  stream,
int  handle,
bool  auto_close = true 
)

Redirects the program output to a file or an already opened file descriptor

Using temporary files
  process prs;
  tempfile tmp("basename");
  prs.redirect_to(process::Stdout, tmp.fd(), true);
Make the object open a file
  process prs;
  prs.redirect_to(process::Stdout, "my_output_file");
Parameters:
stream the output stream, either StdOut or StdErr
handle the file handle to redirect to, or InvalidHandle
auto_close if the file descriptor is owned by this object. If this flag is true, there is no more guarantee as to the status of the file descriptor. It can be closed anytime by the process object

void utilmm::process::redirect_to ( Stream  stream,
FILE *  handle,
bool  auto_close = true 
)

void utilmm::process::redirect_to ( Stream  stream,
boost::filesystem::path const &  file 
)

void utilmm::process::set_environment ( const std::string &  key,
const std::string &  value 
)

Override an environment variable This function sets or overrides an environment variable for the subprocess.

Parameters:
key the variable name
value the variable value

std::string utilmm::process::environment ( const std::string &  key  )  const

Gets an overriden environment variable

Parameters:
key the variable name
Returns:
the variable value if key has previously been overriden by a call to process::set_environment

void utilmm::process::clear_environment (  ) 

Remove any overriden environment variable

void utilmm::process::set_pgid ( pid_t  pid  ) 

Set the process group ID at startup. See setpgid(3)

bool utilmm::process::exit_normal (  )  const

Check if the last running process exited normally

int utilmm::process::exit_status (  )  const

Get the exit status of the last running process

pid_t utilmm::process::pid (  )  const

Get the PID of the last running process

bool utilmm::process::running (  ) 

Check if the process is running


Member Data Documentation

const int utilmm::process::InvalidHandle = -1 [static]


The documentation for this class was generated from the following file:
Generated on Tue Feb 19 10:51:01 2008 for Util-- by doxygen 1.5.3
SourceForge.net Project Page