29#ifndef PT_SYSTEM_PROCESS_H
30#define PT_SYSTEM_PROCESS_H
32#include <Pt/System/Api.h>
33#include <Pt/System/Path.h>
34#include <Pt/System/IODevice.h>
35#include <Pt/System/SystemError.h>
36#include <Pt/NonCopyable.h>
92 { _args.push_back(argument);
return *
this; }
97 {
return _args.size(); }
101 const std::string&
arg(std::size_t idx)
const
102 {
return _args.at(idx); }
121 { _stdinMode = mode; }
136 { _stdoutMode = mode; }
151 { _stderrMode = mode; }
170 std::vector<std::string> _args;
252 class ProcessImpl *_impl;
268 std::string cmdline = _command.toLocal();
270 for( std::size_t i = 0; i < _args.size(); ++i )
271 cmdline +=
' ' + _args[i];
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
Endpoint for I/O operations.
Definition IODevice.h:96
Represents a path in the file-system.
Definition Path.h:48
ProcessFailed()
Default Constructor.
~ProcessFailed()
Destructor.
Definition Process.h:58
Startup parameters for a Process.
Definition Process.h:68
std::size_t argCount() const
Number of command line arguments.
Definition Process.h:96
void setDetached(bool sw)
Process should detach.
Definition Process.h:115
void setStdError(IOMode mode)
Sets I/O flags for stderr.
Definition Process.h:150
ProcessInfo(const Path &command)
Construct with command to execute.
Definition Process.h:256
std::string toString() const
Returns full command line.
Definition Process.h:266
ProcessInfo & addArg(const std::string &argument)
Adds an argument to the list of arguments.
Definition Process.h:91
bool isStdErrorClosed() const
Returns true if stderr will be closed.
Definition Process.h:155
bool isStdInputClosed() const
Returns true if stdin will be closed.
Definition Process.h:125
IOMode
Flags for process I/O.
Definition Process.h:73
@ Redirect
Redirect I/O.
Definition Process.h:76
@ ToStdOut
Combine stderr with stdout, only valid for stderr.
Definition Process.h:77
@ Close
Close I/O.
Definition Process.h:75
@ Keep
Keep open.
Definition Process.h:74
bool isStdInputRedirected() const
Returns true if stdin will be redirected.
Definition Process.h:130
void setStdOutput(IOMode mode)
Sets I/O flags for stdout.
Definition Process.h:135
const std::string & arg(std::size_t idx) const
Returns a command line argument.
Definition Process.h:101
bool isStdOutputClosed() const
Returns true if stdout will be closed.
Definition Process.h:140
void setStdInput(IOMode mode)
Sets I/O flags for stdin.
Definition Process.h:120
const Path & command() const
Command to execute.
Definition Process.h:86
bool isStdErrorAsOutput() const
Returns true if stderr and atdout wil be combined.
Definition Process.h:165
bool isDetached() const
Returns true if process should detach.
Definition Process.h:110
bool isStdOutputRedirected() const
Returns true if stdout will be redirected.
Definition Process.h:145
bool isStdErrorRedirected() const
Returns true if stderr will be redirected.
Definition Process.h:160
Process(const ProcessInfo &procInfo)
Constructs with a process parameters.
bool tryWait(int &status)
Returns true if the process has finished.
State
State of the process.
Definition Process.h:197
@ Ready
Ready to run.
Definition Process.h:198
@ Failed
Execution has failed.
Definition Process.h:201
@ Running
Currently running.
Definition Process.h:199
@ Finished
Finished to run.
Definition Process.h:200
void start()
Start/Create the Process.
IODevice * stdError()
Returns an I/O device to stderr.
IODevice * stdOutput()
Returns an I/O device to stdout.
int wait()
Waits until the Process ends.
IODevice * stdInput()
Returns an I/O device to stdin.
void kill()
Kills the Process.
State state() const
Returns the current state.
const ProcessInfo & procInfo() const
Returns the process parameters.
SystemError(const std::string &what)
Construct with error message.
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33