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];
280 #endif // PT_SYSTEM_PROCESS_H
Core module.
Definition: Allocator.h:33
bool isStdInputRedirected() const
Returns true if stdin will be redirected.
Definition: Process.h:130
IOMode
Flags for process I/O.
Definition: Process.h:73
bool isStdOutputClosed() const
Returns true if stdout will be closed.
Definition: Process.h:140
bool isDetached() const
Returns true if process should detach.
Definition: Process.h:110
int wait()
Waits until the Process ends.
Starts another program as a child process.
Definition: Process.h:192
ProcessFailed()
Default Constructor.
IODevice * stdOutput()
Returns an I/O device to stdout.
Thrown when a process does not terminate normally.
Definition: Process.h:50
void setStdInput(IOMode mode)
Sets I/O flags for stdin.
Definition: Process.h:120
void setDetached(bool sw)
Process should detach.
Definition: Process.h:115
bool isStdOutputRedirected() const
Returns true if stdout will be redirected.
Definition: Process.h:145
@ Redirect
Redirect I/O.
Definition: Process.h:76
~ProcessFailed()
Destructor.
Definition: Process.h:58
bool isStdErrorAsOutput() const
Returns true if stderr and atdout wil be combined.
Definition: Process.h:165
Exception for a failed system operation.
Definition: SystemError.h:45
const ProcessInfo & procInfo() const
Returns the process parameters.
bool isStdErrorRedirected() const
Returns true if stderr will be redirected.
Definition: Process.h:160
@ Keep
Keep open.
Definition: Process.h:74
bool isStdInputClosed() const
Returns true if stdin will be closed.
Definition: Process.h:125
void setStdOutput(IOMode mode)
Sets I/O flags for stdout.
Definition: Process.h:135
IODevice * stdInput()
Returns an I/O device to stdin.
Process(const ProcessInfo &procInfo)
Constructs with a process parameters.
void kill()
Kills the Process.
State
State of the process.
Definition: Process.h:197
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
IODevice * stdError()
Returns an I/O device to stderr.
Represents a path in the file-system.
Definition: Path.h:48
const std::string & arg(std::size_t idx) const
Returns a command line argument.
Definition: Process.h:101
Endpoint for I/O operations.
Definition: IODevice.h:96
@ Close
Close I/O.
Definition: Process.h:75
@ ToStdOut
Combine stderr with stdout, only valid for stderr.
Definition: Process.h:77
State state() const
Returns the current state.
void start()
Start/Create the Process.
std::size_t argCount() const
Number of command line arguments.
Definition: Process.h:96
Base class that disables copy construction and assignment.
Definition: NonCopyable.h:59
const Path & command() const
Command to execute.
Definition: Process.h:86
bool isStdErrorClosed() const
Returns true if stderr will be closed.
Definition: Process.h:155
bool tryWait(int &status)
Returns true if the process has finished.
Startup parameters for a Process.
Definition: Process.h:68
ProcessInfo(const Path &command)
Construct with command to execute.
Definition: Process.h:256
void setStdError(IOMode mode)
Sets I/O flags for stderr.
Definition: Process.h:150
std::string toLocal() const
Returns the path name in local encoding.