Bitcoin Core  27.99.0
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
subprocess::Popen Class Reference

#include <subprocess.h>

Collaboration diagram for subprocess::Popen:
[legend]

Public Member Functions

template<typename... Args>
 Popen (const std::string &cmd_args, Args &&...args)
 
template<typename... Args>
 Popen (std::initializer_list< const char * > cmd_args, Args &&...args)
 
template<typename... Args>
 Popen (std::vector< std::string > vargs_, Args &&... args)
 
int pid () const noexcept
 
int retcode () const noexcept
 
int wait () noexcept(false)
 
int poll () noexcept(false)
 
void kill (int sig_num=9)
 
void set_out_buf_cap (size_t cap)
 
void set_err_buf_cap (size_t cap)
 
int send (const char *msg, size_t length)
 
int send (const std::string &msg)
 
int send (const std::vector< char > &msg)
 
std::pair< OutBuffer, ErrBuffercommunicate (const char *msg, size_t length)
 
std::pair< OutBuffer, ErrBuffercommunicate (const std::string &msg)
 
std::pair< OutBuffer, ErrBuffercommunicate (const std::vector< char > &msg)
 
std::pair< OutBuffer, ErrBuffercommunicate ()
 
FILE * input ()
 
FILE * output ()
 
FILE * error ()
 
void close_input ()
 Stream close APIs. More...
 
void close_output ()
 
void close_error ()
 

Private Member Functions

template<typename F , typename... Args>
void init_args (F &&farg, Args &&... args)
 
void init_args ()
 
void populate_c_argv ()
 
void execute_process () noexcept(false)
 

Private Attributes

detail::Streams stream_
 
std::string exe_name_
 
std::string args_
 
std::vector< std::string > vargs_
 
std::vector< char * > cargv_
 
bool child_created_ = false
 
int child_pid_ = -1
 
int retcode_ = -1
 

Friends

struct detail::ArgumentDeducer
 
class detail::Child
 

Detailed Description

class: Popen This is the single most important class in the whole library and glues together all the helper classes to provide a common interface to the client.

API's provided by the class:

  1. Popen({"cmd"}, output{..}, error{..}, ....) Command provided as a sequence.
  2. Popen("cmd arg1"m output{..}, error{..}, ....) Command provided in a single string.
  3. wait() - Wait for the child to exit.
  4. retcode() - The return code of the exited child.
  5. pid() - PID of the spawned child.
  6. poll() - Check the status of the running child.
  7. kill(sig_num) - Kill the child. SIGTERM used by default.
  8. send(...) - Send input to the input channel of the child.
  9. communicate(...) - Get the output/error from the child and close the channels from the parent side.

input() - Get the input channel/File pointer. Can be used for customizing the way of sending input to child.

  1. output() - Get the output channel/File pointer. Usually used in case of redirection. See piping examples.
  2. error() - Get the error channel/File pointer. Usually used in case of redirection.

Definition at line 970 of file subprocess.h.

Constructor & Destructor Documentation

◆ Popen() [1/3]

template<typename... Args>
subprocess::Popen::Popen ( const std::string &  cmd_args,
Args &&...  args 
)
inline

Definition at line 977 of file subprocess.h.

Here is the call graph for this function:

◆ Popen() [2/3]

template<typename... Args>
subprocess::Popen::Popen ( std::initializer_list< const char * >  cmd_args,
Args &&...  args 
)
inline

Definition at line 990 of file subprocess.h.

Here is the call graph for this function:

◆ Popen() [3/3]

template<typename... Args>
subprocess::Popen::Popen ( std::vector< std::string >  vargs_,
Args &&...  args 
)
inline

Definition at line 1002 of file subprocess.h.

Here is the call graph for this function:

Member Function Documentation

◆ close_error()

void subprocess::Popen::close_error ( )
inline

Definition at line 1077 of file subprocess.h.

◆ close_input()

void subprocess::Popen::close_input ( )
inline

Stream close APIs.

Definition at line 1075 of file subprocess.h.

◆ close_output()

void subprocess::Popen::close_output ( )
inline

Definition at line 1076 of file subprocess.h.

◆ communicate() [1/4]

std::pair<OutBuffer, ErrBuffer> subprocess::Popen::communicate ( )
inline

Definition at line 1065 of file subprocess.h.

Here is the caller graph for this function:

◆ communicate() [2/4]

std::pair<OutBuffer, ErrBuffer> subprocess::Popen::communicate ( const char *  msg,
size_t  length 
)
inline

Definition at line 1046 of file subprocess.h.

Here is the call graph for this function:

◆ communicate() [3/4]

std::pair<OutBuffer, ErrBuffer> subprocess::Popen::communicate ( const std::string &  msg)
inline

Definition at line 1053 of file subprocess.h.

Here is the call graph for this function:

◆ communicate() [4/4]

std::pair<OutBuffer, ErrBuffer> subprocess::Popen::communicate ( const std::vector< char > &  msg)
inline

Definition at line 1058 of file subprocess.h.

Here is the call graph for this function:

◆ error()

FILE* subprocess::Popen::error ( )
inline

Definition at line 1072 of file subprocess.h.

Here is the call graph for this function:

◆ execute_process()

void subprocess::Popen::execute_process ( )
inlineprivatenoexcept

Definition at line 1212 of file subprocess.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_args() [1/2]

void subprocess::Popen::init_args ( )
inlineprivate

Definition at line 1109 of file subprocess.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_args() [2/2]

template<typename F , typename... Args>
void subprocess::Popen::init_args ( F &&  farg,
Args &&...  args 
)
inlineprivate

Definition at line 1114 of file subprocess.h.

Here is the call graph for this function:

◆ input()

FILE* subprocess::Popen::input ( )
inline

Definition at line 1070 of file subprocess.h.

Here is the call graph for this function:

◆ kill()

void subprocess::Popen::kill ( int  sig_num = 9)
inline

Definition at line 1200 of file subprocess.h.

◆ output()

FILE* subprocess::Popen::output ( )
inline

Definition at line 1071 of file subprocess.h.

Here is the call graph for this function:

◆ pid()

int subprocess::Popen::pid ( ) const
inlinenoexcept

Definition at line 1021 of file subprocess.h.

Here is the caller graph for this function:

◆ poll()

int subprocess::Popen::poll ( )
inlinenoexcept

Definition at line 1150 of file subprocess.h.

◆ populate_c_argv()

void subprocess::Popen::populate_c_argv ( )
inlineprivate

Definition at line 1121 of file subprocess.h.

Here is the caller graph for this function:

◆ retcode()

int subprocess::Popen::retcode ( ) const
inlinenoexcept

Definition at line 1023 of file subprocess.h.

Here is the caller graph for this function:

◆ send() [1/3]

int subprocess::Popen::send ( const char *  msg,
size_t  length 
)
inline

Definition at line 1037 of file subprocess.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send() [2/3]

int subprocess::Popen::send ( const std::string &  msg)
inline

Definition at line 1040 of file subprocess.h.

Here is the call graph for this function:

◆ send() [3/3]

int subprocess::Popen::send ( const std::vector< char > &  msg)
inline

Definition at line 1043 of file subprocess.h.

Here is the call graph for this function:

◆ set_err_buf_cap()

void subprocess::Popen::set_err_buf_cap ( size_t  cap)
inline

Definition at line 1035 of file subprocess.h.

Here is the call graph for this function:

◆ set_out_buf_cap()

void subprocess::Popen::set_out_buf_cap ( size_t  cap)
inline

Definition at line 1033 of file subprocess.h.

Here is the call graph for this function:

◆ wait()

int subprocess::Popen::wait ( )
inlinenoexcept

Definition at line 1129 of file subprocess.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ detail::ArgumentDeducer

friend struct detail::ArgumentDeducer
friend

Definition at line 973 of file subprocess.h.

◆ detail::Child

friend class detail::Child
friend

Definition at line 974 of file subprocess.h.

Member Data Documentation

◆ args_

std::string subprocess::Popen::args_
private

Definition at line 1097 of file subprocess.h.

◆ cargv_

std::vector<char*> subprocess::Popen::cargv_
private

Definition at line 1100 of file subprocess.h.

◆ child_created_

bool subprocess::Popen::child_created_ = false
private

Definition at line 1102 of file subprocess.h.

◆ child_pid_

int subprocess::Popen::child_pid_ = -1
private

Definition at line 1104 of file subprocess.h.

◆ exe_name_

std::string subprocess::Popen::exe_name_
private

Definition at line 1094 of file subprocess.h.

◆ retcode_

int subprocess::Popen::retcode_ = -1
private

Definition at line 1106 of file subprocess.h.

◆ stream_

detail::Streams subprocess::Popen::stream_
private

Definition at line 1087 of file subprocess.h.

◆ vargs_

std::vector<std::string> subprocess::Popen::vargs_
private

Definition at line 1099 of file subprocess.h.


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