Skip to content

process std_stream

Alairion edited this page May 8, 2021 · 6 revisions

nes::process::stdin_stream, nes::process::stdout_stream, nes::process::stderr_stream

Functions

(1) pipe_ostream& stdin_stream() noexcept;
(2) pipe_istream& stdout_stream() noexcept;
(3) pipe_istream& stderr_stream() noexcept;

These functions returns a pipe on the standard streams of the process (stdin, stdout, stderr). These functions are defined only if the file "pipe.hpp" is present.

The references on the pipes are not invalidated if the process object is moved, i.e. the pipes have static addresses.
They share their lifetime with the process object, but you can move them and then become responsible of their lifetimes.

These pipes have the same behaviour as the ones defined in <nes/pipe.hpp>, so it can turn into deadlocks if not used correctly.
If you close/destroy a grabbed stream, the child can run into an error if it use the other end of the closed/destroyed stream.
Also, you should not call join before all grabbed streams become "end-of-file" because it can deadlock both processes if the child is still using them.
The pipes stay valid after a call to detach and still have all properties listed above, so you must keep them alive as long as the child is running.

These pipes will become "end-of-file" after a call to join, or a successful call to kill because the other end will be closed.

  1. Get the pipe linked to the process standard input.
  2. Get the pipe linked to the process standard output.
  3. Get the pipe linked to the process standard error.

Parameters

None.

Return value

  1. Returns a reference on a pipe that is the write end of the process standard input.
  2. Returns a reference on a pipe that is the read end of the process standard output.
  3. Returns a reference on a pipe that is the read end of the process standard error.

Preconditions

The file "pipe.hpp" must be present.

  1. nes::process_options::grab_stdin must has been specified in the process creation.
  2. nes::process_options::grab_stdout must has been specified in the process creation.
  3. nes::process_options::grab_stderr must has been specified in the process creation.

Exceptions

Does not throw.

Clone this wiki locally