Commit | Line | Data |
---|---|---|
57e7635d TL |
1 | .TH POPEN 3S |
2 | .SH NAME | |
3 | popen, pclose \- initiate I/O to/from a process | |
4 | .SH SYNOPSIS | |
5 | .B #include <stdio.h> | |
6 | .PP | |
7 | .SM | |
8 | .B FILE | |
9 | .B *popen(command, type) | |
10 | .br | |
11 | .B char *command, *type; | |
12 | .PP | |
13 | .B pclose(stream) | |
14 | .br | |
15 | .SM | |
16 | .B FILE | |
17 | .B *stream; | |
18 | .SH DESCRIPTION | |
19 | The arguments to | |
20 | .I popen | |
21 | are pointers to null-terminated strings | |
22 | containing respectively a shell command line and an I/O | |
23 | mode, either "r" for reading or "w" for | |
24 | writing. | |
25 | It creates a pipe between | |
26 | the calling process and | |
27 | the command to be executed. | |
28 | The value returned | |
29 | is a stream pointer that | |
30 | can be used (as appropriate) to write to the standard input | |
31 | of the command or read from its standard output. | |
32 | .PP | |
33 | A stream opened by | |
34 | .I popen | |
35 | should be closed by | |
36 | .I pclose, | |
37 | which waits for the associated process to terminate | |
38 | and returns the exit status of the command. | |
39 | .PP | |
40 | Because open files are shared, a type "r" command | |
41 | may be used as an input filter, | |
42 | and a type "w" as an output filter. | |
43 | .SH "SEE ALSO" | |
44 | pipe(2), | |
45 | fopen(3), | |
46 | fclose(3), | |
47 | system(3), | |
48 | wait(2) | |
49 | .SH DIAGNOSTICS | |
50 | .I Popen | |
51 | returns a null pointer | |
52 | if files or processes cannot be created, or the Shell | |
53 | cannot be accessed. | |
54 | .PP | |
55 | .I Pclose | |
56 | returns \-1 if | |
57 | .I stream | |
58 | is not associated with a `popened' command. | |
59 | .SH BUGS | |
60 | Buffered reading before opening an input filter | |
61 | may leave the standard input of that filter mispositioned. | |
62 | Similar problems with an output filter may be | |
63 | forestalled by careful buffer flushing, e.g. with | |
64 | .I fflush, | |
65 | see | |
66 | .IR fclose (3). |