libcommonc++
0.7
|
A system process. More...
#include <Process.h++>
Public Member Functions | |
Process (const String &path, const StringVec &args, const StringVec &env=StringVec::emptyVec, const String &workingDir=".") | |
Construct a new Process. More... | |
~Process () | |
Destructor. More... | |
void | start () |
Start the process. More... | |
void | stop () |
Stop the process. More... | |
bool | kill () |
Forcibly kill the process. More... | |
void | setPriority (Priority priority) |
Set the process priority. More... | |
Priority | getPriority () const |
Get the process priority. More... | |
bool | waitFor (ExitStatus &status) |
Wait for the process to terminate. More... | |
bool | isStarted () const |
Determine if the process has been started. More... | |
Stream & | getInputStream () |
Get the input stream for the process. More... | |
Stream & | getOutputStream () |
Get the output stream for the process. More... | |
Stream & | getErrorStream () |
Get the error stream for the process. More... | |
time_ms_t | getStartTime () const |
Get the time at which the process was started. More... | |
Static Public Member Functions | |
static void | exit (int status) |
Terminate the calling process. More... | |
static String | getProgramName () |
Get the name of the calling program. More... | |
static String | getExecutablePath () |
Get the full path to the calling program's executable file. More... | |
static String | getExecutableDir () |
Get the full path to the directory containing the calling program's executable file. More... | |
static void | setProgramName (const char *name) |
Set the name of the calling program. More... | |
static String | getWorkingDir () |
Get the calling process's working directory. More... | |
static bool | setWorkingDir (const String &path) |
Set the calling process's working directory. More... | |
static bool | hasConsole () |
Test for the presence of a console. More... | |
static bool | getConsoleSize (uint_t *columns, uint_t *rows) |
Get the console dimensions for the calling process, in characters. More... | |
static void | setConsoleTitle (const String &title) |
Set the console title for the calling process. More... | |
static ProcessID | currentProcessID () |
Get the calling process ID. More... | |
A system process.
This class may be used to execute a program, communicate with the program via its standard I/O streams, terminate the program, and collect its exit status. The class also includes a number of static utility functions that affect the current process.
When the Process is created, its standard input, output, and error streams are automatically connected to the parent process; these streams can be accessed using the getInputStream(), getOutputStream(), and getErrorStream() methods. Any output that the process produces on its standard output and error streams must be read in a timely manner by the calling process to avoid deadlock. Alternatively, if the calling process is not interested in the output, it can immediately close these streams.
Process | ( | const String & | path, |
const StringVec & | args, | ||
const StringVec & | env = StringVec::emptyVec , |
||
const String & | workingDir = "." |
||
) |
Construct a new Process.
path | The path to the executable. |
args | The command-line arguments for the executable. |
env | Environment variable settings for the new process. |
workingDir | The working directory for the new process. |
~Process | ( | ) |
Destructor.
The destructor does not terminate the process.
|
static |
Get the calling process ID.
|
static |
Terminate the calling process.
status | The exit status to exit with. |
Get the console dimensions for the calling process, in characters.
On POSIX systems, this refers to the dimensions of the terminal window. On Windows, it refers to the "console buffer size."
columns | A pointer to the value where the width of the console should be stored. May be NULL. |
rows | A pointer to the value where the height of the console should be stored. May be NULL. |
|
inline |
Get the error stream for the process.
This stream is connected to the standard error of the process.
|
static |
Get the full path to the directory containing the calling program's executable file.
SystemException | If an error occurs. |
|
static |
Get the full path to the calling program's executable file.
SystemException | If an error occurs. |
|
inline |
Get the input stream for the process.
This stream is connected to the standard input of the process.
|
inline |
Get the output stream for the process.
This stream is connected to the standard output of the process.
Priority getPriority | ( | ) | const |
Get the process priority.
|
inlinestatic |
Get the name of the calling program.
|
inline |
Get the time at which the process was started.
|
static |
Get the calling process's working directory.
|
static |
Test for the presence of a console.
|
inline |
Determine if the process has been started.
bool kill | ( | ) |
Forcibly kill the process.
If the process has not been started, this method has no effect.
|
static |
Set the console title for the calling process.
title | The new title. |
void setPriority | ( | Priority | priority | ) |
Set the process priority.
|
inlinestatic |
Set the name of the calling program.
|
static |
Set the calling process's working directory.
path | The new working directory. |
void start | ( | ) |
Start the process.
If the process has already been started, this method has no effect.
SystemException | If an error occurred. |
void stop | ( | ) |
Stop the process.
On Windows systems, this method has the same effect as kill(). On POSIX systems, this method sends a (catchable) SIGTERM signal to the process. If the process has not been started, this method has no effect.
bool waitFor | ( | ExitStatus & | status | ) |
Wait for the process to terminate.
Once a process has exited (for whatever reason) and its exit status has been collected via a call to this method, it can be started again with start().
status | The object in which to store the exit status. |