Go to the documentation of this file.
24 #include <sys/types.h>
51 open (
const string& cmd_,
const string& type_)
55 #if !defined(WIN32) // not yet implemented
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;
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.
Fork class is a simple wrapper around C library function fork(). Main advantage of using Fork over fo...
A simple wrapper around fork() library function call.
FILE * open(const string &cmd_, const string &type_)
Starts a subshell and feed it the string cmd_ to be executed.
int close()
Close the pipe.
int fd() const
Get pipe's file descriptor.
bool isChild() const
Test whether we are in child section of the code.
Pipe()
A no-op constructor.
@ IGNORE_STATUS
Don't wait for child to complete.
@ ASSAERR
ASSA and system errors
@ PIPE
Class Pipe messages
@ KILL_ON_EXIT
Kill all childer on exit.
pid_t m_child_pid
Supbrocess' PID.
pid_t getChildPID() const
Retrieve child process id.
#define trace_with_mask(s, m)