Initiates a pipe to a process.
Standard C Library (libc.a)
FILE *popen (Command, Type) const char *Command, *Type;
The popen subroutine creates a pipe between the calling program and a shell command to be executed.
Note: The popen subroutine runs only sh shell commands. The results are unpredictable if the Command parameter is not a valid sh shell command. If the terminal is in a trusted state, the tsh shell commands are run.
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.
Attention: If the original processes and the process started with the popen subroutine concurrently read or write a common file, neither should use buffered I/O. If they do, the results are unpredictable.
Some problems with an output filter can be prevented by flushing the buffer with the fflush subroutine.
|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.
This subroutine is part of Base Operating System (BOS) Runtime.
The fclose or fflush subroutine, fopen, freopen, or fdopen subroutine, fork or vfork subroutine, pclose subroutine, pipe subroutine, wait, waitpid, or wait3 subroutine.
Input and Output Handling Programmer's Overview.
Files, Directories, and File Systems for Programmers in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.