Add Process functions for detached spawning

This commit is contained in:
Robbert van der Helm
2022-04-14 16:39:34 +02:00
parent 1df7abfb2c
commit 75b3cf266d
5 changed files with 152 additions and 16 deletions
+24 -1
View File
@@ -94,7 +94,8 @@ class ProcessEnvironment {
/**
* A child process whose output can be captured. Simple wrapper around the Posix
* APIs.
* APIs. The functions provided for running processes this way are very much
* tailored towards yabridge's needs.
*/
class Process {
public:
@@ -110,6 +111,8 @@ class Process {
protected:
Handle(pid_t pid);
friend Process;
public:
/**
* Terminates the process when it gets dropped.
@@ -195,6 +198,26 @@ class Process {
*/
StatusResult spawn_get_status() const;
/**
* Spawn the process without waiting for its completion, leave STDIN alone,
* create pipes for STDOUT and STDERR, and assign those to the provided
* (empty) stream descriptors. Use `posix_spawn()`, closes all non-STDIO
* file descriptors. The process will be terminated when the child process
* handle gets dropped.
*/
HandleResult spawn_child_piped(
asio::posix::stream_descriptor& stdout_pipe,
asio::posix::stream_descriptor& stderr_pipe) const;
/**
* Spawn the process without waiting for its completion, leave STDIN alone,
* and redirect STDOUT and STDERR to a file. Use `posix_spawn()`, closes all
* non-STDIO file descriptors. The process will be terminated when the child
* process handle gets dropped.
*/
HandleResult spawn_child_redirected(
const ghc::filesystem::path& filename) const;
private:
/**
* Create the `argv` array from the command and the arguments. Only valid as