Cypress  1.0
C++ Spiking Neural Network Simulation Framework
Public Member Functions | Static Public Member Functions | List of all members
cypress::Process Class Reference

#include <process.hpp>

Public Member Functions

 Process (const std::string &cmd, const std::vector< std::string > &args, bool do_redirect=true)
 
 ~Process ()
 
std::istream & child_stdout ()
 
std::istream & child_stderr ()
 
std::ostream & child_stdin ()
 
void close_child_stdin ()
 
bool running ()
 
int exitcode ()
 
int wait ()
 
bool signal (int signal)
 

Static Public Member Functions

static void generic_writer (Process &proc, std::istream &input)
 
static void generic_pipe (std::istream &input, std::ostream &output)
 
static void fd_input_pipe (int fd, std::ostream &output, const std::atomic< bool > &done)
 
static int exec (const std::string &cmd, const std::vector< std::string > &args, std::ostream &cout, std::ostream &cerr, const std::string &input=std::string())
 
static int exec (const std::string &cmd, const std::vector< std::string > &args, std::istream &cin, std::ostream &cout, std::ostream &cerr)
 
static int exec_no_redirect (const std::string &cmd, const std::vector< std::string > &args)
 
static std::tuple< int, std::string, std::string > exec (const std::string &cmd, const std::vector< std::string > &args, const std::string &input=std::string())
 

Detailed Description

The Process class represents a child process and its input/output streams.

Constructor & Destructor Documentation

cypress::Process::Process ( const std::string &  cmd,
const std::vector< std::string > &  args,
bool  do_redirect = true 
)

Constructor of the process class. Executes the given command with the given arguments.

Parameters
cmdis the command that should be executed.
argsis a vector of arguments that should be passed to the command.
cypress::Process::~Process ( )

Destroys the process instance. Waits for the child process to exit.

Member Function Documentation

std::istream& cypress::Process::child_stderr ( )

Returns a reference at the child process standard error stream.

Returns
a reference at a C++ input stream from which the standard error of the child process can be read.
std::ostream& cypress::Process::child_stdin ( )

Returns a reference at the child process standard input stream. Note: use the close_child_stdin() method to close this stream.

Returns
a reference at a C++ output stream which can be used to write data to the standard input of the child process.
std::istream& cypress::Process::child_stdout ( )

Returns a reference at the child process standard out stream.

Returns
a reference at a C++ input stream from which the standard output of the child process can be read.
void cypress::Process::close_child_stdin ( )

Closes the childs standard in stream.

static int cypress::Process::exec ( const std::string &  cmd,
const std::vector< std::string > &  args,
std::ostream &  cout,
std::ostream &  cerr,
const std::string &  input = std::string() 
)
static

Convenience method for executing a child process and sendings its stdout and stderr streams to the given streams.

Parameters
cmdis the command that should be executed.
argsis a vector of arguments that should be given to the command.
coutis the target stream to which the child process cout should be written.
cerris the target stream to which the child process cerr should be written.
inputis a string that should be sent to the child process via its stdin.
Returns
the process return code.
static int cypress::Process::exec ( const std::string &  cmd,
const std::vector< std::string > &  args,
std::istream &  cin,
std::ostream &  cout,
std::ostream &  cerr 
)
static

Convenience method for executing a child process and sendings its stdout and stderr streams to the given streams.

Parameters
cmdis the command that should be executed.
argsis a vector of arguments that should be given to the command.
cinis a stream which should be sent to the child process.
coutis the target stream to which the child process cout should be written.
cerris the target stream to which the child process cerr should be written.
Returns
the process return code.
static std::tuple<int, std::string, std::string> cypress::Process::exec ( const std::string &  cmd,
const std::vector< std::string > &  args,
const std::string &  input = std::string() 
)
static

Convenience method for executing a child process, sending data via stdin and receiving its output on std::cout and std::cerr.

Parameters
cmdis the command that should be executed.
argsis a vector of arguments that should be given to the command.
inputis a string that should be sent to the child process via its stdin.
Returns
a tuple containing the exit code and the output from stdout and stderr (in this order).
static int cypress::Process::exec_no_redirect ( const std::string &  cmd,
const std::vector< std::string > &  args 
)
static

Convenience method for executing a child process without redirecting stdin/stdout/stderr.

Parameters
cmdis the command that should be executed.
argsis a vector of arguments that should be given to the command.
Returns
the process return code.
int cypress::Process::exitcode ( )

Returns the exitcode of the process, as a value between 0 and 255. If the child process was killed by a signal, returns the signal number which killed the process as a negative number. The result is only valid if the child process is no longer running (running() return false, or wait() returned).

Returns
the exit code (positive number) or the signal number which killed the child process (negative number).
static void cypress::Process::fd_input_pipe ( int  fd,
std::ostream &  output,
const std::atomic< bool > &  done 
)
static

Thread proc used to asynchronously pipe data from a source filedescriptor to the target stream.

Parameters
fdis the input file descriptor.
outputis the target stream.
doneshould be set to true when the thread should no longer listen on the fd.
static void cypress::Process::generic_pipe ( std::istream &  input,
std::ostream &  output 
)
static

Thread proc used to asynchronously pipe data from a source input stream to a target stream. Used to read data from a process.

Parameters
inputis the input stream.
outputis the target stream.
static void cypress::Process::generic_writer ( Process proc,
std::istream &  input 
)
static

Thread proc used to asynchronously stream an input stream to a process.

Parameters
procis the process to which should be written.
inputis the stream that should be written to the stdin of the process.
bool cypress::Process::running ( )

Returns true if the child process is still running, false otherwise.

bool cypress::Process::signal ( int  signal)

Sends a UNIX signal to the child process, corresponding to the kill system call.

Parameters
signalis the UNIX signal that should be sent to the child process.
Returns
true if the operation was successful, false if not, e.g. because the child no longer exists.
int cypress::Process::wait ( )

Waits for the child process to exit. Returns the exitcode. See exitcode() for the exact semantics.


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