Manual Page Result
0
Command: popen | Section: 3 | Source: UNIX v10 | File: popen.3
POPEN(3S) POPEN(3S)
NAME
popen, ppopen, vepopen, pclose - open a pipe to/from a process
SYNOPSIS
#include <stdio.h>
FILE *popen(command, type)
char *command, *type;
FILE *ppopen(command, type)
char *command, *type;
FILE *vepopen(command, type, args, env)
char *command, *type, **args, **env;
int pclose(stream)
FILE *stream;
DESCRIPTION
The first argument to popen is a pointer to a null-terminated string
containing a command line for sh(1). Type is as in fopen(3). Popen
creates a pipe between the calling process and the command and returns
a stream pointer that can be used to write to the standard input of the
command or to read from the standard output.
Ppopen uses the -p shell flag to restrict the environment of the shell.
Both popen and ppopen set the effective userid to the real userid be-
fore calling the shell.
Vepopen has arguments akin to those of execve (see exec(2)): a file to
be executed, a mode as above, a null-terminated vector of argument
strings, and a null-terminated vector of environment strings. The
shell is not called, and the effective userid is preserved.
A stream opened by these routines should be closed by pclose, which
waits for the associated process to terminate and returns the exit sta-
tus of the command.
Because the command inherits open files, in particular standard input
and output, a type "r" call may be used to insert a filter in the in-
put, and type "w" in the output.
SEE ALSO
exec(2), pipe(2), fopen(3), stdio(3), system(3)
DIAGNOSTICS
Popen returns a null pointer if files or processes cannot be created,
or the Shell cannot be accessed.
Pclose returns -1 if there is no process to wait for.
BUGS
Buffered reading before opening an input filter may leave the standard
input of that filter mispositioned. Similar problems with an output
filter may be forestalled by calling fflush; see fopen(3).
The resetting of the userid is probably gratuitous; it is there as a
defense against incautious use of the routine by set-uid programs.
I/O type "r+w" exists but is not useful.
POPEN(3S)