vpopen(3) CLIX vpopen(3)
NAME
vpopen - Initiates a pipe to/from a process
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <stdio.h>
FILE *vpopen(
char *command ,
char *type );
PARAMETERS
command A shell command line.
type A character flag representing a read or write mode.
DESCRIPTION
The vpopen() function creates a pipe between the calling program and the
command to be executed.
The arguments to vpopen() are pointers to null-terminated strings. The
command parameter consists of a shell command line. The parameter type is
an I/O mode, either r for reading or w for writing. The value returned is
a stream pointer such that one can write to stdin of the command by
writing to the file stream, if the I/O mode is w. Also, if the I/O mode
is r, one can read from stdout of the command by reading from the file
stream.
Since open files are shared, a type r command may be used as an input
filter, and a type w may be used as an output filter.
EXAMPLE
A typical call may be as follows:
char *cmd = "ls *.c";
FILE *ptr;
if ((ptr = vpopen(cmd, "r")) != NULL)
while (fgets(buf, n, ptr) != NULL)
(void) printf("%s",buf);
This example displays, in stdout (see stdio(4)), all the filenames in the
current directory having a .c suffix.
2/94 - Intergraph Corporation 1
vpopen(3) CLIX vpopen(3)
NOTES
The vpopen() function is equivalent to the popen() function, except that
vpopen() uses vfork() instead of fork() for more efficient memory usage.
CAUTIONS
If the original and the vpopen()ed processes read or write a common file
concurrently, neither should use buffered I/O. This causes a buffering
mix-up. Prevent output filter problems by using careful buffer flushing;
for example, using fflush(). Also, refer to fclose(3).
RETURN VALUES
If files or processes cannot be created, vpopen() returns a NULL pointer.
RELATED INFORMATION
Functions: popen(3), fork(2), vfork(2), pipe(2), wait(2), fclose(3),
fopen(3), system(3)
Files: stdio(4)
2 Intergraph Corporation - 2/94