|
subprocess 0.5.0
Modern subprocess library for c++
|
Namespaces | |
| namespace | details |
Classes | |
| struct | CalledProcessError |
| struct | CommandNotFoundError |
| struct | CompletedProcess |
| class | CwdGuard |
| class | EnvGuard |
| class | Environ |
| class | EnvironSetter |
| struct | OSError |
| struct | PipePair |
| struct | Popen |
| class | ProcessBuilder |
| struct | RunBuilder |
| struct | RunOptions |
| struct | SpawnError |
| class | StopWatch |
| struct | SubprocessError |
| struct | TimeoutExpired |
Typedefs | |
| typedef intptr_t | ssize_t |
| typedef int | PipeHandle |
| typedef ::pid_t | pid_t |
| typedef std::vector< std::string > | CommandLine |
| typedef std::map< std::string, std::string > | EnvMap |
| typedef std::variant< PipeOption, std::string, PipeHandle, std::istream *, std::ostream *, FILE * > | PipeVar |
Enumerations | |
| enum | SigNum { PSIGHUP = 1 , PSIGINT = SIGINT , PSIGQUIT = 3 , PSIGILL = SIGILL , PSIGTRAP = 5 , PSIGABRT = SIGABRT , PSIGIOT = 6 , PSIGBUS = 7 , PSIGFPE = SIGFPE , PSIGKILL = 9 , PSIGUSR1 = 10 , PSIGSEGV = SIGSEGV , PSIGUSR2 = 12 , PSIGPIPE = 13 , PSIGALRM = 14 , PSIGTERM = SIGTERM , PSIGSTKFLT = 16 , PSIGCHLD = 17 , PSIGCONT = 18 , PSIGSTOP = 19 , PSIGTSTP = 20 , PSIGTTIN = 21 , PSIGTTOU = 22 , PSIGURG = 23 , PSIGXCPU = 24 , PSIGXFSZ = 25 , PSIGVTALRM = 26 , PSIGPROF = 27 , PSIGWINCH = 28 , PSIGIO = 29 } |
| enum class | PipeOption : int { inherit , cout , cerr , specific , pipe , close } |
| enum class | PipeVarIndex { option , string , handle , istream , ostream , file } |
Functions | |
| EnvMap | current_env_copy () |
| ssize_t | pipe_peak_bytes (PipeHandle pipe) |
| bool | pipe_close (PipeHandle handle) |
| PipePair | pipe_create (bool inheritable=false) |
| void | pipe_set_inheritable (PipeHandle handle, bool inheritable) |
| ssize_t | pipe_read (PipeHandle, void *buffer, size_t size) |
| ssize_t | pipe_write (PipeHandle, const void *buffer, size_t size) |
| bool | pipe_set_blocking (PipeHandle, bool should_block) |
| void | pipe_ignore_and_close (PipeHandle handle) |
| std::string | pipe_read_all (PipeHandle handle) |
| int | pipe_wait_for_read (PipeHandle pipe, double seconds) |
| ssize_t | pipe_read_some (PipeHandle, void *buffer, size_t size) |
| PipeHandle | pipe_file (const char *filename, const char *mode) |
| PipeOption | get_pipe_option (const PipeVar &option) |
| CompletedProcess | run (Popen &popen, bool check=false) |
| CompletedProcess | run (CommandLine command, RunOptions options={}) |
| double | monotonic_seconds () |
| double | sleep_seconds (double seconds) |
| std::string | getenv (const std::string &var) |
| std::string | find_program (const std::string &name) |
| void | find_program_clear_cache () |
| std::string | escape_shell_arg (std::string arg) |
| std::string | getcwd () |
| void | setcwd (const std::string &path) |
| std::string | abspath (std::string dir, std::string relativeTo="") |
Variables | |
| constexpr bool | kIsWin32 = false |
| constexpr char | kPathDelimiter = ':' |
| const PipeHandle | kBadPipeValue = (PipeHandle)-1 |
| constexpr int | kStdInValue = 0 |
| constexpr int | kStdOutValue = 1 |
| constexpr int | kStdErrValue = 2 |
| constexpr int | kBadReturnCode = -1000 |
| Environ | cenv |
| typedef std::vector<std::string> subprocess::CommandLine |
| typedef std::map<std::string, std::string> subprocess::EnvMap |
| typedef ::pid_t subprocess::pid_t |
| typedef int subprocess::PipeHandle |
| typedef std::variant<PipeOption, std::string, PipeHandle, std::istream*, std::ostream*, FILE*> subprocess::PipeVar |
| typedef intptr_t subprocess::ssize_t |
|
strong |
Redirect destination
|
strong |
| enum subprocess::SigNum |
Signals to send. they start with P because SIGX are macros, P stands for Posix as these values are as defined by Posix.
| std::string subprocess::abspath | ( | std::string | dir, |
| std::string | relativeTo = "" |
||
| ) |
Converts dir to be absolute path.
| dir | The path you want to be absolute. |
| relativeTo | If specified use this instead of the current working directory. |
| EnvMap subprocess::current_env_copy | ( | ) |
Creates a copy of current environment variables and returns the map
| std::string subprocess::escape_shell_arg | ( | std::string | arg | ) |
Escapes the argument suitable for use on command line.
| std::string subprocess::find_program | ( | const std::string & | name | ) |
Searches for program in PATH environment variable.
on windows tries adding suffixes specified in PATHEXT environment variable.
on windows an input of "python3" will also search "python" executables and inspect their version to find an executable that offers python 3.x.
| void subprocess::find_program_clear_cache | ( | ) |
Clears cache used by find_program.
find_program uses internal cache to find executables. If you modify PATH using subprocess::cenv this will be called automatically for you. If a new program is added to a folder with the same name as an existing program you may want to clear the cache so that the new program is found as expected instead of the old program being returned.
|
inline |
| std::string subprocess::getcwd | ( | ) |
Gets the current working directory of the process
| std::string subprocess::getenv | ( | const std::string & | var | ) |
Get the value of environment variable
| double subprocess::monotonic_seconds | ( | ) |
| bool subprocess::pipe_close | ( | PipeHandle | handle | ) |
Closes a pipe handle.
| handle | The handle to close. |
| PipePair subprocess::pipe_create | ( | bool | inheritable = false | ) |
Creates a pair of pipes for input/output
| inheritable | if true subprocesses will inherit the pipe. |
| OSError | if system call fails. |
| PipeHandle subprocess::pipe_file | ( | const char * | filename, |
| const char * | mode | ||
| ) |
Opens a file and returns the handle.
You must call pipe_close() on the returned handle. When using as a parameter to Popen or run(), pipe_close should not be called as ownership will be taken.
| filename | The file path |
| mode | The mode as from fopen. Always binary mode. r - read only, will fail if file doesn't exist w - write only and will create or truncate the file
|
| void subprocess::pipe_ignore_and_close | ( | PipeHandle | handle | ) |
Spawns a thread to read from the pipe. When no more data available pipe will be closed.
| ssize_t subprocess::pipe_peak_bytes | ( | PipeHandle | pipe | ) |
Peak into how many bytes available in pipe to read.
| ssize_t subprocess::pipe_read | ( | PipeHandle | , |
| void * | buffer, | ||
| size_t | size | ||
| ) |
| std::string subprocess::pipe_read_all | ( | PipeHandle | handle | ) |
Read contents of handle until no more data is available.
If the pipe is non-blocking this will end prematurely.
| ssize_t subprocess::pipe_read_some | ( | PipeHandle | , |
| void * | buffer, | ||
| size_t | size | ||
| ) |
Will read up to size and not block until buffer is filled.
| bool subprocess::pipe_set_blocking | ( | PipeHandle | , |
| bool | should_block | ||
| ) |
Sets the blocking bit.
The handle state is first queried as to only change the blocking bit.
| should_block | If false then pipe_read/write will exit early if there is no blocking. |
| void subprocess::pipe_set_inheritable | ( | PipeHandle | handle, |
| bool | inheritable | ||
| ) |
Set the pipe to be inheritable or not for subprocess.
| OSError | if system call fails. |
| inheritable | if true handle will be inherited in subprocess. |
| int subprocess::pipe_wait_for_read | ( | PipeHandle | pipe, |
| double | seconds | ||
| ) |
Waits for the pipes to be change state.
| pipes | pointer to first pipe in an array |
| did_change | pointer to an output of the first pipe that changed state |
| count | number of pipes |
| seconds | The timeout in seconds to wait for. -1 for indefinate |
| ssize_t subprocess::pipe_write | ( | PipeHandle | , |
| const void * | buffer, | ||
| size_t | size | ||
| ) |
| CompletedProcess subprocess::run | ( | CommandLine | command, |
| RunOptions | options = {} |
||
| ) |
Run a command blocking until completion.
see subprocess::run(Popen&,bool) for more details about exceptions.
| command | The command to run. First element must be executable. |
| options | Options specifying how to run the command. |
| CompletedProcess subprocess::run | ( | Popen & | popen, |
| bool | check = false |
||
| ) |
If you have stuff to pipe this will run the process to completion.
This will read stdout/stderr if they exist and store in cout, cerr.
| popen | An already running process. |
| check | if true will throw CalledProcessException if process returns non-zero exit code. |
| CalledProcessError | if check=true and process returned non-zero error code |
| TimeoutExpired | if subprocess does not finish by timeout seconds. |
| OSError | for os level exceptions such as failing OS commands. |
| std::runtime_error | for various errors. |
| std::invalid_argument | if argument is invalid for current usage. |
| std::domain_error | when arguments don't make sense working together |
| void subprocess::setcwd | ( | const std::string & | path | ) |
Sets the current working directory of process.
| double subprocess::sleep_seconds | ( | double | seconds | ) |
Sleep for a number of seconds.
| seconds | The number of seconds to sleep for. |
|
extern |
Makes it easy to get/set environment variables. e.g. like so subprocess::cenv["VAR"] = "Value";
| const PipeHandle subprocess::kBadPipeValue = (PipeHandle)-1 |
The value representing an invalid pipe
|
constexpr |
The value representing an invalid exit code possible for a process.
|
constexpr |
|
constexpr |
The path seperator for PATH environment variable.
|
constexpr |
|
constexpr |
|
constexpr |