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