Process related utilities. More...
Classes | |
| struct | sourcemeta::core::ProcessInput |
| struct | sourcemeta::core::ProcessOutput |
| class | sourcemeta::core::ProcessProgramNotFoundError |
| class | sourcemeta::core::ProcessSpawnError |
Functions | |
| SOURCEMETA_CORE_PROCESS_EXPORT auto | sourcemeta::core::spawn (const std::string &program, std::initializer_list< std::string_view > arguments, const ProcessInput &input={}) -> int |
| SOURCEMETA_CORE_PROCESS_EXPORT auto | sourcemeta::core::spawn (const std::string &program, std::span< const std::string_view > arguments, const ProcessInput &input={}) -> int |
| SOURCEMETA_CORE_PROCESS_EXPORT auto | sourcemeta::core::spawn_and_capture (const std::string &program, std::initializer_list< std::string_view > arguments, const ProcessInput &input={}) -> ProcessOutput |
| SOURCEMETA_CORE_PROCESS_EXPORT auto | sourcemeta::core::spawn_and_capture (const std::string &program, std::span< const std::string_view > arguments, const ProcessInput &input={}) -> ProcessOutput |
Process related utilities.
This functionality is included as follows:
| struct sourcemeta::core::ProcessInput |
The settings for running a program.
Every member carries a default so that naming only the ones that matter stays free of missing-initializer warnings.
Public Attributes | |
| std::filesystem::path | directory {std::filesystem::current_path()} |
| std::optional< std::map< std::string_view, std::string_view > > | environment |
| std::string_view | standard_input {} |
| std::filesystem::path sourcemeta::core::ProcessInput::directory {std::filesystem::current_path()} |
The working directory of the program. It must be an absolute path to an existing directory
| std::optional<std::map<std::string_view, std::string_view> > sourcemeta::core::ProcessInput::environment |
The entire environment of the program, replacing rather than extending the environment of the caller. Without a value, the caller's environment is inherited as it stands. The referenced names and values must outlive the call
| std::string_view sourcemeta::core::ProcessInput::standard_input {} |
The bytes to feed the program on its standard input. The referenced buffer must outlive the call
| struct sourcemeta::core::ProcessOutput |
The result of running a program while capturing what it writes.
Public Attributes | |
| std::optional< int > | exit_code {std::nullopt} |
| std::string | standard_output {} |
| Everything the program wrote to its standard output. | |
| std::string | standard_error {} |
| Everything the program wrote to its standard error. | |
| std::optional<int> sourcemeta::core::ProcessOutput::exit_code {std::nullopt} |
The code the program exited with, or no value if it terminated abnormally, such as by a signal
| class sourcemeta::core::ProcessProgramNotFoundError |
An executable program could not be found
Public Member Functions | |
| ProcessProgramNotFoundError (const std::string_view program) | |
| Construct the error given the offending program. | |
| auto | program () const noexcept -> std::string_view |
| The offending program. | |
| class sourcemeta::core::ProcessSpawnError |
A spawned process terminated abnormally
Public Member Functions | |
| ProcessSpawnError (const std::string_view program, std::initializer_list< std::string_view > arguments) | |
| Construct the error given the offending program and its arguments. | |
| ProcessSpawnError (const std::string_view program, std::span< const std::string_view > arguments) | |
| Construct the error given the offending program and its arguments. | |
| auto | program () const noexcept -> std::string_view |
| The offending program. | |
| auto | arguments () const noexcept -> const std::vector< std::string > & |
| The arguments the program was spawned with. | |
| SOURCEMETA_CORE_PROCESS_EXPORT auto sourcemeta::core::spawn | ( | const std::string & | program, |
| std::initializer_list< std::string_view > | arguments, | ||
| const ProcessInput & | input = {} ) -> int |
Spawn a program piping its output to the current stdio configuration.
| SOURCEMETA_CORE_PROCESS_EXPORT auto sourcemeta::core::spawn | ( | const std::string & | program, |
| std::span< const std::string_view > | arguments, | ||
| const ProcessInput & | input = {} ) -> int |
Spawn a program piping its output to the current stdio configuration. This overload accepts a span for dynamic argument lists.
| SOURCEMETA_CORE_PROCESS_EXPORT auto sourcemeta::core::spawn_and_capture | ( | const std::string & | program, |
| std::initializer_list< std::string_view > | arguments, | ||
| const ProcessInput & | input = {} ) -> ProcessOutput |
Spawn a program, feeding it the given input and capturing both of its output streams in full.
| SOURCEMETA_CORE_PROCESS_EXPORT auto sourcemeta::core::spawn_and_capture | ( | const std::string & | program, |
| std::span< const std::string_view > | arguments, | ||
| const ProcessInput & | input = {} ) -> ProcessOutput |
Spawn a program, feeding it the given input and capturing both of its output streams in full. This overload accepts a span for dynamic argument lists.