Starts a subshell and feed it the string cmd_ to be executed.
The pipe is created and attached to the standard input or standard output of the subprocess, according to whether type_ is either "r" (read) or "w" (write). The other end of the pipe is returned to the calling code as a standard I/O stream, FILE, ready for buffered use with fprintf(), fscanf(), fgets, etc.
- See also
- Fork
- Parameters
-
cmd_ | command to execute |
type_ | "w" for write pipe and "r" for read pipe |
- Returns
- pointer to a standard I/O stream. In case of error, NULL is returned with errno set to indicate the type of error encountered.
Definition at line 50 of file Pipe.cpp.
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) {
#define EL(X)
A macro for writing error message to the Logger.
Fork class is a simple wrapper around C library function fork().
@ KILL_ON_EXIT
Kill all childer on exit.
@ IGNORE_STATUS
Don't wait for child to complete.
int fd() const
Get pipe's file descriptor.
References ASSA::ASSAERR, close(), DL, EL, fd(), ASSA::Fork::getChildPID(), ASSA::Fork::IGNORE_STATUS, ASSA::Fork::isChild(), ASSA::Fork::KILL_ON_EXIT, m_child_pid, m_fp, ASSA::PIPE, and trace_with_mask.