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