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