subprocess::command class

Main interface class for subprocess library.

A class that contains a list of linked shell commands and is responsible for managing their file descriptors such that their input and output can be chained to other commands.

Constructors, destructors, conversion operators

command(std::string cmd) explicit

Public functions

auto run() -> int
Runs the command pipeline and throws on error.
auto run(std::nothrow_t) -> int
Runs the command pipeline and doesn't throw.
auto operator|(command&& other) -> command&
Chains a command object to the current one.
auto operator|(std::string other) -> command&

Friends

auto operator<(command& cmd, descriptor_ptr fd) -> command&
auto operator>(command& cmd, err_t err_tag) -> command&
auto operator>(command& cmd, descriptor_ptr fd) -> command&
auto operator>=(command& cmd, out_t out_tag) -> command&
auto operator>=(command& cmd, descriptor_ptr fd) -> command&

Function documentation

int subprocess::command::run()

Runs the command pipeline and throws on error.

Returns int Return code from the pipeline

run only returns when the return code from the pipeline is 0. Otherwise, it throws subprocess::exceptions::command_error.

It can also throw exceptions::os_error if the command could not be run due to some operating system level restrictions/errors.

int subprocess::command::run(std::nothrow_t)

Runs the command pipeline and doesn't throw.

Returns int Return code from the pipeline

run(nothrow_t) returns the exit code from the pipeline. It doesn't throw subprocess::exceptions::command_error.

However, it can still throw exceptions::os_error in case of operating system level restrictions/errors.

command& subprocess::command::operator|(command&& other)

Chains a command object to the current one.

Parameters
other Command ob
Returns command&

The output of the current command object is piped into the other command object.

Currently, the argument can only be an r-value because of open file descriptors. This will be changed soon.