24 #include <sys/types.h>
51 open (
const string& cmd_,
const string& type_)
57 if (type_ !=
"r" && type_ !=
"w") {
58 EL((
ASSAERR,
"Wrong type \"%s\"\n", type_.c_str ()));
73 if (
fd [1] != STDOUT_FILENO) {
74 dup2 (
fd [1], STDOUT_FILENO);
80 if (
fd [0] != STDIN_FILENO) {
81 dup2 (
fd [0], STDIN_FILENO);
86 DL((
PIPE,
"Executing cmd: \"%s\"\n", cmd_.c_str ()));
87 execl (
"/bin/sh",
"sh",
"-c", cmd_.c_str (), (
char* ) 0);
94 if ((
m_fp = fdopen (
fd [0], type_.c_str ())) == NULL) {
101 if ((
m_fp = fdopen (
fd [1], type_.c_str ())) == NULL) {
150 return ret == EOF ? -1 : 0;
A simple wrapper around fork() library function call.
#define EL(X)
A macro for writing error message to the Logger.
#define DL(X)
A macro for writing debug message to the Logger.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
A wrapper around UNIX popen()/pclose() standard library calls.
Fork class is a simple wrapper around C library function fork().
@ KILL_ON_EXIT
Kill all childer on exit.
bool isChild() const
Test whether we are in child section of the code.
@ IGNORE_STATUS
Don't wait for child to complete.
pid_t getChildPID() const
Retrieve child process id.
pid_t m_child_pid
Supbrocess' PID.
int fd() const
Get pipe's file descriptor.
Pipe()
A no-op constructor.
FILE * open(const string &cmd_, const string &type_)
Starts a subshell and feed it the string cmd_ to be executed.
FILE * m_fp
A standard I/O stream descriptor.
int kill()
Kill subprocess with SIGTERM.
~Pipe()
Destructor calls close () first in an attempt to close opened pipe.
int close()
Close the pipe.
@ PIPE
Class Pipe messages
@ ASSAERR
ASSA and system errors