Skip to content

process_options

Alairion edited this page May 8, 2021 · 4 revisions

nes::process_options

Defined in header <nes/process.hpp>

enum class process_options : std::uint32_t
{
    none = 0x00,
#ifdef NES_PROCESS_PIPE_EXTENSION
    grab_stdout = 0x10,
    grab_stderr = 0x20,
    grab_stdin = 0x40 
#endif
};

Description

nes::process_options is an enumeration that defines additional flags that can be given to nes::process's constructor.
nes::process_options is a bitmask type.

grab_stdout, grab_stderr and grab_stdin values are only defined if the file "pipe.hpp" is present.

Values

Name Description
none No additional parameters, i.e. does nothing
grab_stdout Tells the nes::process's constructor to redirect (grab) the standard output of the new process. (see nes::process::stdout_stream)
grab_stderr Tells the nes::process's constructor to redirect (grab) the standard error of the new process. (see nes::process::stderr_stream)
grab_stdin Tells the nes::process's constructor to redirect (grab) the standard input of the new process. (see nes::process::stdin_stream)

Example

Here is an example in which we create a child process with redirected standard output.
main.cpp is the main file of the parent process.
other.cpp is the main file of the child process.
Output is the standard output of the parent process.

main.cpp

#include <iostream>

#include <nes/process.hpp>

int main()
{
    //Create a child process, and grab its standard output.
    nes::process other{"other_process", nes::process_options::grab_stdout};
    
    //Read the entire standard output of the child process.
    std::cout << other.stdout_stream().rdbuf() << std::endl;

    if(other.joinable())
        other.join();
}

other.cpp

#include <iostream>

int main()
{
    //Display something
    std::cout << "Hello world! I'm Other!" << std::endl;
}

Output

Hello world! I'm Other!
Clone this wiki locally