popen(3S)popen(3S)NAMEpopen(), pclose() - initiate pipe I/O to/from a process
SYNOPSISDESCRIPTION
creates a pipe between the calling program and a command to be executed
by the POSIX shell, (see sh-posix(1)).
The arguments to are pointers to null-terminated strings containing,
respectively, a shell command line and an I/O mode, either for reading
or for writing.
returns a stream pointer such that one can write to the standard input
of the command if the I/O mode is by writing to the file stream; and
one can read from the standard output of the command if the I/O mode is
by reading from the file stream.
Because open files are shared, a type command can be used as an input
filter and a type command as an output filter. If mode is other than
or the result is undefined.
A stream opened by should be closed by which waits for the associated
process to terminate and returns the exit status of the command. How‐
ever, if a call caused the termination status to be unavailable to then
returns -1 with errno set to This can happen in one of the following
conditions:
· If the signal handler for is set to
· If the signal handler or another thread in the same process issues
or call.
APPLICATION USAGE
After a stream is associated with a pipe by the stream is byte-oriented
(see orientation(5)).
RETURN VALUE
Upon successful completion, returns a pointer to an open stream that
can be used to read or write to the pipe. Otherwise, it returns a NULL
pointer if files or processes cannot be created and set errno to indi‐
cate the error. The success of the command execution can be checked by
examining the return value of
Upon successful return, returns the termination status of the command
language interpreter. Otherwise, returns -1 if stream is not associ‐
ated with a command and set errno to indicate the error.
ERRORS
The function fails if:
The maximum number of file descriptors allowed are currently open.
The function fails if:
The status of the child process is not available.
WARNINGS
If the original and processes concurrently read or write a common file,
neither should use buffered I/O because the buffering will not work
properly. Problems with an output filter can be forestalled by careful
buffer flushing, e.g., with see fclose(3S).
SEE ALSOpipe(2), wait(2), fclose(3S), fopen(3S), system(3S), orientation(5),
thread_safety(5).
STANDARDS CONFORMANCEpopen(3S)