Turi Create
4.0
|
#include <core/system/platform/process/process.hpp>
Public Member Functions | |
bool | launch (const std::string &cmd, const std::vector< std::string > &args) |
bool | popen (const std::string &cmd, const std::vector< std::string > &args, int target_child_write_fd, bool open_write_pipe=false) |
ssize_t | read_from_child (void *buf, size_t count) |
bool | write_to_child (const void *buf, size_t count) |
bool | kill (bool async=true) |
bool | exists () |
int | get_return_code () |
void | set_nonblocking (bool nonblocking) |
void | autoreap () |
Cross platform process launching, and management.
Definition at line 42 of file process.hpp.
void turi::process::autoreap | ( | ) |
Mark that this process should be automatically reaped. In which case, get_return_code() will not work.
bool turi::process::exists | ( | ) |
Check if the process launched is running.
Throws if process was never launched.
int turi::process::get_return_code | ( | ) |
Return the process's return code if it has exited.
Returns INT_MIN if the process is still running. Returns INT_MAX if getting the error code failed for some other reason.
bool turi::process::kill | ( | bool | async = true | ) |
Kill the launched process
Throws if process was never launched.
bool turi::process::launch | ( | const std::string & | cmd, |
const std::vector< std::string > & | args | ||
) |
A "generic" process launcher.
Launched the command with the given arguments as a separate child process.
This function does not throw.
bool turi::process::popen | ( | const std::string & | cmd, |
const std::vector< std::string > & | args, | ||
int | target_child_write_fd, | ||
bool | open_write_pipe = false |
||
) |
A generic implementation of popen in read mode.
This means that whatever the child writes on the given file descriptor (target_child_write_fd) can be read by calling read_from_child. On Unix systems, this could be any file descriptor inherited by the child from the parent. On Windows, we only accept STDOUT_FILENO and STDERR_FILENO.
NOTE: The STD*_FILENO constants are Unix specific, but defined in this header for convenience.
For instance, if target_child_write_fd == STDOUT_FILENO, when child writes to STDOUT, the parent can use read_from_child to read it.
if target_child_write_fd == STDERR_FILENO, when child writes to STDERR, the parent can use read_from_child to read it.
if open_write_pipe == true, write_to_child can be used.
This function does not throw.
ssize_t turi::process::read_from_child | ( | void * | buf, |
size_t | count | ||
) |
If we've set up a way to read from the child, use this to read.
Returns -1 on error, otherwise bytes received
Throws if a way to read was not set up or if process was not launched.
void turi::process::set_nonblocking | ( | bool | nonblocking | ) |
Sets O_NONBLOCK on the process if the argument is true.
bool turi::process::write_to_child | ( | const void * | buf, |
size_t | count | ||
) |
Writes to the child's stdin.
Returns false on error.
Throws if a way to read was not set up or if process was not launched.