21 #ifndef G_NEW_PROCESS_H
22 #define G_NEW_PROCESS_H
23 #define G_NEW_PROCESS_WITH_WAIT_FUTURE
37 class NewProcessWaitFuture ;
48 G_EXCEPTION( CannotFork ,
"cannot fork()" ) ;
49 G_EXCEPTION( WaitError ,
"cannot wait()" ) ;
50 G_EXCEPTION( ChildError ,
"child process terminated abnormally or stopped" ) ;
51 G_EXCEPTION( Insecure ,
"refusing to exec() while the user-id is zero" ) ;
52 G_EXCEPTION( PipeError ,
"pipe error" ) ;
53 G_EXCEPTION( InvalidPath ,
"invalid executable path -- must be absolute" ) ;
54 G_EXCEPTION( CreateProcessError ,
"CreateProcess() error" ) ;
57 int capture_stdxxx = 1 ,
bool clean =
true ,
bool strict_path =
true ,
59 int exec_error_exit = 127 ,
60 const std::string & exec_error_format = std::string() ,
61 std::string (*exec_error_format_fn)(std::string,
int) = 0 ) ;
108 static std::pair<bool,pid_t>
fork() ;
117 static std::string execErrorFormat(
const std::string & ,
int ) ;
160 std::vector<char> m_buffer ;
void kill()
Tries to kill the spawned process.
static Identity invalid()
Returns an invalid identity.
A class that holds the parameters and the results of a waitpid() system call.
A combination of user-id and group-id, with a very low-level interface to the get/set/e/uid/gid funct...
std::vector< std::string > StringArray
A std::vector of std::strings.
NewProcess(const Path &exe, const StringArray &args, int capture_stdxxx=1, bool clean=true, bool strict_path=true, Identity run_as_id=Identity::invalid(), bool strict_id=true, int exec_error_exit=127, const std::string &exec_error_format=std::string(), std::string(*exec_error_format_fn)(std::string, int)=0)
Constructor.
static std::pair< bool, pid_t > fork()
A utility function that forks the calling process and returns twice; once in the parent and once in t...
std::string output()
Returns the first bit of child-process output.
NewProcessWaitFuture & run()
Waits for the process identified by the constructor parameter to exit.
NewProcessWaitFuture & wait()
Returns a reference to the WaitFuture sub-object so that the caller can wait for the child process to...
NewProcessWaitFuture()
Default constructor for an object where run() does nothing and get() returns zero.
A pimple-pattern implementation class used by G::NewProcess.
A Path object represents a file system path.
A class for creating new processes.