Initiates a pipe to a process.
Standard C Library (libc.a)
The popen subroutine creates a pipe between the calling program and a shell command to be executed.
If streams opened by previous calls to the popen subroutine remain open in the parent process, the popen subroutine closes them in the child process.
The popen subroutine returns a pointer to a FILE structure for the stream.
Some problems with an output filter can be prevented by flushing the buffer with the fflush subroutine.
Item | Description |
---|---|
Command | Points to a null-terminated string containing a shell command line. |
Type | Points to a null-terminated string containing an I/O mode.
If the Type parameter is the value r, you can read from
the standard output of the command by reading from the file Stream.
If the Type parameter is the value w, you can write
to the standard input of the command by writing to the file Stream.
Because open files are shared, a type r command can be used as an input filter and a type w command as an output filter. |
The popen subroutine returns a null pointer if files or processes cannot be created, or if the shell cannot be accessed.
The popen subroutine may set the EINVAL variable if the Type parameter is not valid. The popen subroutine may also set errno global variables as described by the fork or pipe subroutines.