subprocess  0.4.0
Modern subprocess library for c++
Public Member Functions | Public Attributes | List of all members
subprocess::Popen Struct Reference

#include <ProcessBuilder.hpp>

Public Member Functions

 Popen ()
 
 Popen (CommandLine command, const RunOptions &options)
 
 Popen (CommandLine command, RunOptions &&options)
 
 Popen (const Popen &)=delete
 
Popenoperator= (const Popen &)=delete
 
 Popen (Popen &&)
 
Popenoperator= (Popen &&)
 
 ~Popen ()
 
void ignore_cout ()
 
void ignore_cerr ()
 
void ignore_output ()
 
bool poll ()
 
int wait (double timeout=-1)
 
bool send_signal (int signal)
 
bool terminate ()
 
bool kill ()
 
void close ()
 
void close_cin ()
 

Public Attributes

PipeHandle cin = kBadPipeValue
 
PipeHandle cout = kBadPipeValue
 
PipeHandle cerr = kBadPipeValue
 
pid_t pid = 0
 
int returncode = kBadReturnCode
 
CommandLine args
 
friend ProcessBuilder
 

Detailed Description

Active running process.

Similar design of subprocess.Popen. In c++ I didn't like

Constructor & Destructor Documentation

◆ Popen() [1/5]

subprocess::Popen::Popen ( )
inline

Initialized as empty and invalid

◆ Popen() [2/5]

subprocess::Popen::Popen ( CommandLine  command,
const RunOptions options 
)

Starts command with specified options

◆ Popen() [3/5]

subprocess::Popen::Popen ( CommandLine  command,
RunOptions &&  options 
)

Starts command with specified options

◆ Popen() [4/5]

subprocess::Popen::Popen ( const Popen )
delete

◆ Popen() [5/5]

subprocess::Popen::Popen ( Popen &&  )

◆ ~Popen()

subprocess::Popen::~Popen ( )

Waits for process, Closes pipes and destroys any handles.

Member Function Documentation

◆ close()

void subprocess::Popen::close ( )

Destructs the object and initializes to basic state

◆ close_cin()

void subprocess::Popen::close_cin ( )
inline

Closes the cin pipe

◆ ignore_cerr()

void subprocess::Popen::ignore_cerr ( )
inline

calls pipe_ignore_and_close on cerr

◆ ignore_cout()

void subprocess::Popen::ignore_cout ( )
inline

calls pipe_ignore_and_close on cout

◆ ignore_output()

void subprocess::Popen::ignore_output ( )
inline

calls pipe_ignore_and_close on cout, cerr if open

◆ kill()

bool subprocess::Popen::kill ( )

equivalent to send_signal(SIGKILL)

◆ operator=() [1/2]

Popen& subprocess::Popen::operator= ( const Popen )
delete

◆ operator=() [2/2]

Popen& subprocess::Popen::operator= ( Popen &&  )

◆ poll()

bool subprocess::Popen::poll ( )
Returns
true if terminated.
Exceptions
OSErrorIf os specific error has been encountered.

◆ send_signal()

bool subprocess::Popen::send_signal ( int  signal)

Send the signal to the process.

On windows SIGKILL does TerminateProcess, SIGINT sends CTRL_C_EVENT, and anything else including SIGTERM sends CTRL_BREAK_EVENT. It is important to note that such signals is sent to all processes including your own and parents. This might result in your application being terminated if you don't handle CTRL_BREAK_EVENT or CTRL_C_EVENT. To mitigate this set the new process group flag using RunBuilder::new_progress_group() to true.

This deviates from pythons subprocess library behavior in which SIGTERM does the equivalent of SIGKILL in python.

◆ terminate()

bool subprocess::Popen::terminate ( )

Sends SIGTERM, on windows sends CTRL_BREAK_EVENT

◆ wait()

int subprocess::Popen::wait ( double  timeout = -1)

Waits for process to finish.

If stdout or stderr is not read from, the child process may be blocked when it tries to write to the respective streams. You must ensure you continue to read from stdout/stderr. Call ignore_output() to spawn threads to ignore the output preventing a deadlock. You can also troll the child by closing your end.

Parameters
timeouttimeout in seconds. Raises TimeoutExpired on timeout. NOT IMPLEMENTED, WILL WAIT FOREVER.
Returns
returncode
Exceptions
OSErrorIf there was an os level error call OS API's
TimeoutExpiredIf the timeout has expired.

Member Data Documentation

◆ args

CommandLine subprocess::Popen::args

◆ cerr

PipeHandle subprocess::Popen::cerr = kBadPipeValue

Read from this stream to get cerr output of process. This class holds the ownership and will call pipe_close().

◆ cin

PipeHandle subprocess::Popen::cin = kBadPipeValue

Write to this stream to send data to the process. This class holds the ownership and will call pipe_close().

◆ cout

PipeHandle subprocess::Popen::cout = kBadPipeValue

Read from this stream to get output of process. This class holds the ownership and will call pipe_close().

◆ pid

pid_t subprocess::Popen::pid = 0

◆ ProcessBuilder

friend subprocess::Popen::ProcessBuilder

◆ returncode

int subprocess::Popen::returncode = kBadReturnCode

The exit value of the process. Valid once process is completed


The documentation for this struct was generated from the following file: