Bell 32V release
[unix-history] / usr / man / man3 / popen.3s
CommitLineData
57e7635d
TL
1.TH POPEN 3S
2.SH NAME
3popen, 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
19The arguments to
20.I popen
21are pointers to null-terminated strings
22containing respectively a shell command line and an I/O
23mode, either "r" for reading or "w" for
24writing.
25It creates a pipe between
26the calling process and
27the command to be executed.
28The value returned
29is a stream pointer that
30can be used (as appropriate) to write to the standard input
31of the command or read from its standard output.
32.PP
33A stream opened by
34.I popen
35should be closed by
36.I pclose,
37which waits for the associated process to terminate
38and returns the exit status of the command.
39.PP
40Because open files are shared, a type "r" command
41may be used as an input filter,
42and a type "w" as an output filter.
43.SH "SEE ALSO"
44pipe(2),
45fopen(3),
46fclose(3),
47system(3),
48wait(2)
49.SH DIAGNOSTICS
50.I Popen
51returns a null pointer
52if files or processes cannot be created, or the Shell
53cannot be accessed.
54.PP
55.I Pclose
56returns \-1 if
57.I stream
58is not associated with a `popened' command.
59.SH BUGS
60Buffered reading before opening an input filter
61may leave the standard input of that filter mispositioned.
62Similar problems with an output filter may be
63forestalled by careful buffer flushing, e.g. with
64.I fflush,
65see
66.IR fclose (3).