POPEN(3,L) AIX Technical Reference POPEN(3,L)
-------------------------------------------------------------------------------
popen, pclose, rpopen
PURPOSE
Initiates a pipe to or from a process.
LIBRARY
Standard I/O Library (libc.a)
SYNTAX
#include <stdio.h> #include <stdio.h>
#include sys </types.h>
FILE *popen (command, type) FILE *rpopen (command, type, site)
char *command, *type; char *command, *type;
siteno_t site;
int pclose (stream)
FILE *stream;
DESCRIPTION
The popen subroutine creates a pipe between the calling program and a shell
command to be executed.
The command parameter points to a null-terminated string containing a shell
command line. The type parameter pointers to a null-terminated string
containing an I/O mode, either r for reading or w for writing.
The popen subroutine returns a pointer to a FILE structure for the stream. If
the type parameter is r, you can read from the standard output of the command
by reading from the file stream. If the type parameter is w, you can write to
the standard input of the command by writing to the file stream.
If the Transparent Computing Facility is installed, the rpopen subroutine is
available. The rpopen subroutine is similar to popen, but takes an additional
parameter to specify the cluster site on which to run the shell command. If
site is 0, the current site is used (which is identical to popen).
Processed November 7, 1990 POPEN(3,L) 1
POPEN(3,L) AIX Technical Reference POPEN(3,L)
Use the pclose subroutine to close any stream you have opened with the popen or
rpopen subroutine. The pclose subroutine waits for the associated process to
terminate and then returns the exit status of the command.
Because open files are shared, a type r command can be used as an input filter
and a type w as an output filter.
Warning: If the original processes and the process started with popen
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 taking care to flush
the buffer with the fflush subroutine (see "fclose, fflush").
The popen and rpopen subroutines return a NULL pointer if files or processes
cannot be created, or if the shell cannot be accessed.
The pclose subroutine returns -1 if stream is not associated with a popen
command.
ERROR CONDITIONS
The pclose subroutine fails if the following is true:
ECHILD The status of the child process could not be obtained.
RELATED INFORMATION
In this book: "fclose, fflush," "fopen, freopen, fdopen," "pipe," "stdio,"
"system," and "wait, waitpid."
Processed November 7, 1990 POPEN(3,L) 2