Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Struct process_stdio

boost::process::v2::process_stdio — The initializer for the stdio of a subprocess.

Synopsis

// In header: <boost/process/v2/stdio.hpp>


struct process_stdio {

  // public member functions
  error_code on_exec_setup(posix::default_launcher &, 
                           const filesystem::path &, const char *const *);

  // public data members
  unspecified in;
  unspecified out;
  unspecified err;
};

Description

The subprocess initializer has three members:

  • in for stdin

  • out for stdout

  • err for stderr

If the initializer is present all three will be set for the subprocess. By default they will inherit the stdio handles from the parent process. This means that this will forward stdio to the subprocess:

asio::io_context ctx;
v2::process proc(ctx, "/bin/bash", {}, v2::process_stdio{});

No constructors are provided in order to support designated initializers in later version of C++.

  • asio::io_context ctx;
    v2::process proc17(ctx, "/bin/bash", {}, v2::process_stdio{.stderr=nullptr});
    v2::process proc17(ctx, "/bin/bash", {}, v2::process_stdio{ {}, {}, nullptr});
                                                           stdin ^  ^ stderr
    

Valid initializers for any stdio are:

  • std::nullptr_t assigning a null-device

  • FILE* any open file, including stdin, stdout and stderr

  • a filesystem::path, which will open a readable or writable depending on the direction of the stream

  • native_handle any native file handle (HANDLE on windows) or file descriptor (int on posix)

  • any io-object with a .native_handle() function that is compatible with the above. E.g. a asio::ip::tcp::socket

  • an asio::basic_writeable_pipe for stdin or asio::basic_readable_pipe for stderr/stdout.

process_stdio public member functions

  1. error_code on_exec_setup(posix::default_launcher & launcher, 
                             const filesystem::path &, const char *const *);

PrevUpHomeNext