Line | |
---|
1 | .\" @(#)popen.3 6.1 (Berkeley) 5/15/85
|
---|
2 | .\"
|
---|
3 | .TH POPEN 3 "May 15, 1985"
|
---|
4 | .AT 3
|
---|
5 | .SH NAME
|
---|
6 | popen, pclose \- initiate I/O to/from a process
|
---|
7 | .SH SYNOPSIS
|
---|
8 | .nf
|
---|
9 | .ft B
|
---|
10 | #include <stdio.h>
|
---|
11 |
|
---|
12 | FILE *popen(const char *command, const char *type)
|
---|
13 | int pclose(FILE *stream)
|
---|
14 | .SH DESCRIPTION
|
---|
15 | The arguments to
|
---|
16 | .B popen
|
---|
17 | are pointers to null-terminated strings containing respectively a
|
---|
18 | shell command line and an I/O mode, either "r" for reading or "w" for
|
---|
19 | writing. It creates a pipe between the calling process and
|
---|
20 | the command to be executed. The value returned is a stream pointer that
|
---|
21 | can be used (as appropriate) to write to the standard input
|
---|
22 | of the command or read from its standard output.
|
---|
23 | .PP
|
---|
24 | A stream opened by
|
---|
25 | .B popen
|
---|
26 | should be closed by
|
---|
27 | .BR pclose ,
|
---|
28 | which waits for the associated process to terminate
|
---|
29 | and returns the exit status of the command.
|
---|
30 | .PP
|
---|
31 | Because open files are shared, a type "r" command may be used as an input
|
---|
32 | filter, and a type "w" as an output filter.
|
---|
33 | .SH "SEE ALSO"
|
---|
34 | .BR pipe (2),
|
---|
35 | .BR fopen (3),
|
---|
36 | .BR fclose (3),
|
---|
37 | .BR system (3),
|
---|
38 | .BR wait (2),
|
---|
39 | .BR sh (1).
|
---|
40 | .SH DIAGNOSTICS
|
---|
41 | .B Popen
|
---|
42 | returns a null pointer if files or processes cannot be created, or the shell
|
---|
43 | cannot be accessed.
|
---|
44 | .SH BUGS
|
---|
45 | Buffered reading before opening an input filter
|
---|
46 | may leave the standard input of that filter mispositioned.
|
---|
47 | Similar problems with an output filter may be
|
---|
48 | forestalled by careful buffer flushing, for instance, with
|
---|
49 | .BR fflush ,
|
---|
50 | see
|
---|
51 | .BR fclose (3).
|
---|
Note:
See
TracBrowser
for help on using the repository browser.