16 #ifndef _BASIS_SUBPROCESS_H 17 #define _BASIS_SUBPROCESS_H 28 # include <sys/types.h> 53 typedef HANDLE PipeHandle;
55 typedef int PipeHandle;
60 typedef PROCESS_INFORMATION Information;
108 static CommandLine
split(
const std::string& cmd);
117 static std::string
tostring(
const CommandLine& args);
143 bool popen(
const CommandLine& args,
148 const Environment* env = NULL);
177 const Environment* env = NULL)
179 return popen(
split(cmd), rm_in, rm_out, rm_err, env);
260 bool communicate(std::istream& in, std::ostream& out, std::ostream& err);
276 bool communicate(std::ostream& out, std::ostream& err);
300 int write(
const void* buf,
size_t nbuf);
313 int read(
void* buf,
size_t nbuf,
bool err =
false);
336 static int call(
const CommandLine& cmd);
355 static int call(
const std::string& cmd);
391 #endif // _BASIS_SUBPROCESS_H RedirectMode
Modes of redirection for standard input/output buffers.
std::vector< std::string > CommandLine
bool kill()
Kill subprocess.
bool popen(const CommandLine &args, const RedirectMode rm_in=RM_NONE, const RedirectMode rm_out=RM_NONE, const RedirectMode rm_err=RM_NONE, const Environment *env=NULL)
Open new subprocess.
int write(const void *buf, size_t nbuf)
Write data to stdin of subprocess.
System related macro definitions.
Do not redirect the input/output.
bool send_signal(int signal)
Send signal to subprocess.
Redirect stderr to stdout.
static int call(const CommandLine &cmd)
Execute command as subprocess.
int read(void *buf, size_t nbuf, bool err=false)
Read data from stdout or stderr of subprocess.
bool wait()
Wait for subprocess to terminate.
std::vector< std::string > Environment
Platform-independent interface to create and control a subprocess.
bool terminate()
Terminate subprocess.
bool popen(const std::string &cmd, const RedirectMode rm_in=RM_NONE, const RedirectMode rm_out=RM_NONE, const RedirectMode rm_err=RM_NONE, const Environment *env=NULL)
Open new subprocess.
Subprocess()
Default constructor.
static std::string tostring(const CommandLine &args)
Convert argument vector to double quoted string.
Use a pipe to redirect the input/output from/to the parent.
static CommandLine split(const std::string &cmd)
Split double quoted string into arguments.
~Subprocess()
Terminate running subprocess and close all related handles.
bool communicate(std::istream &in, std::ostream &out, std::ostream &err)
Communicate with subprocess.
bool poll() const
Check if subprocess terminated and update return code.