47 #ifndef _MIRA_EXECUTEPROCESS_H_ 48 #define _MIRA_EXECUTEPROCESS_H_ 54 #include <boost/noncopyable.hpp> 55 #include <boost/optional.hpp> 56 #include <boost/iostreams/device/file_descriptor.hpp> 57 #include <boost/iostreams/stream.hpp> 79 std::string* oStdOut=NULL,
80 std::string* oErrOut=NULL);
130 void insert(
const std::string& var,
const std::string&
value);
139 void insert(
const std::string&
string);
153 void remove(
const std::string& var);
156 const std::string&
value(
const std::string& var,
const std::string& defaultValue = std::string())
const;
163 std::vector<std::string>
envp();
168 const std::map<std::string,std::string>&
variables()
const {
return mVariables; }
176 std::map<std::string,std::string> mVariables;
264 const std::vector<std::string>& args,
267 boost::optional<Environment> env = boost::optional<Environment>());
338 typedef boost::iostreams::stream<boost::iostreams::file_descriptor_sink>
ostream;
339 typedef boost::iostreams::stream<boost::iostreams::file_descriptor_source>
istream;
377 bool mShutdownRecursively;
379 boost::shared_ptr<ostream> mCinFd;
380 boost::shared_ptr<istream> mCoutFd;
381 boost::shared_ptr<istream> mCerrFd;
ostream & cin()
Output stream for writing to the stdin of the child process.
Process()
Creates an invalid process object.
static Process createProcess(const std::string &commandLine, CreationFlags flags, RedirectionFlags streamRedirection=none)
Spawns a new process and executes the given command line.
Environment()
Definition: Process.h:116
Definition: Process.h:218
Macros for generating logical operators for using enum values as flags.
const std::map< std::string, std::string > & variables() const
Definition: Process.h:168
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Definition: Process.h:219
void insert(const std::string &var, const std::string &value)
inserts or replaces the environment variable var with the given value.
Time and Duration wrapper class.
void clear()
Removes all environment variables.
bool isRunning()
Returns if the process that is represented by this Process object is still running.
const std::string & value(const std::string &var, const std::string &defaultValue=std::string()) const
returns the value of the environment variable var, or the default value, if it does not exist...
Definition: Process.h:100
#define MIRA_ENUM_TO_FLAGS_INCLASS(EnumType)
Macro that can be used with enums that contain flags.
Definition: EnumToFlags.h:143
Environment & operator=(const Environment &other)
Encapsulates a process, that was launched from the current process.
Definition: Process.h:93
int getExitCode()
Return the exit code of the process.
Definition: Process.h:203
void shutdown(Duration timeout=Duration::seconds(5))
Performs an orderly shutdown by executing the following steps.
boost::iostreams::stream< boost::iostreams::file_descriptor_sink > ostream
Definition: Process.h:338
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:280
Use this class to represent time durations.
Definition: Time.h:106
uint32 getPID() const
Returns the process id (pid) of the process.
static Environment systemEnvironment()
std::vector< std::string > envp()
Generates and returns an vector of strings, conventionally of the form key=value, which can be used t...
Definition: Process.h:221
void setRecursiveShutdown(bool recursive)
Enable recursive shutdown.
static Duration infinity()
Returns a special duration time representing positive infinity.
Definition: Time.h:242
void insertList(const std::string &string)
Inserts all variables from the given string which has the format.
istream & cout()
Input stream for reading from the stdout of the child process.
CreationFlags
Definition: Process.h:202
If true, shutdown will determine the complete progeny of the spawned process and eradicate it (top do...
Definition: Process.h:212
int executeProcess(const std::string &cmd, std::string *oStdOut=NULL, std::string *oErrOut=NULL)
Executes a given command/process.
void interrupt()
Stops (e.g.
void terminate()
Terminates (e.g.
istream & cerr()
Input stream for reading from the stderr of the child process.
ExitStatus getExitStatus()
Returns the exit status of the process only valid if not running.
std::vector< int > getRecursiveChildProcesses(int pid, int maxDepth=-1)
ExitStatus
Definition: Process.h:96
~Process()
Destructor, which will terminate the process, if it is still running.
Will send the SIGINT signal to the child when the parent gets killed.
Definition: Process.h:206
RedirectionFlags
Definition: Process.h:217
Definition: Process.h:220
boost::iostreams::stream< boost::iostreams::file_descriptor_source > istream
Definition: Process.h:339
Holds the environment variables that can be passed to a process.
Definition: Process.h:113
Process & operator=(Process &&other) noexcept
void swap(Process &other)
Swaps the ownership of the process context within this and other.
bool wait(Duration maxWait=Duration::infinity())
Blocks the current thread of the calling process, until the process that is represented by this Proce...