|
|
1.1 root 1: .\" @(#)popen.3 6.2 (Berkeley) 12/7/88
2: .\"
3: .TH POPEN 3 "December 7, 1988"
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
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
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
34: .IR pclose ,
35: which waits for the associated process to terminate
36: and returns the exit status of the command.
37: .PP
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.
40: .SH "SEE ALSO"
41: sh(1), pipe(2), wait4(2), fclose(3), fopen(3), system(3)
42: .SH DIAGNOSTICS
43: .I Popen
44: returns a null pointer if files or processes cannot be created, or the shell
45: cannot be accessed.
46: .PP
47: .I Pclose
48: returns \-1 if
49: .I stream
50: is not associated with a `popened' command, or if
51: .I stream
52: already `pclosed', or
53: .IR wait (4)
54: returns an error.
55: .SH BUGS
56: Buffered reading before opening an input filter
57: may leave the standard input of that filter mispositioned.
58: Similar problems with an output filter may be
59: forestalled by careful buffer flushing, for instance, with
60: .I fflush,
61: see
62: .IR fclose (3).
63: .LP
64: .I Popen
65: always calls
66: .IR sh ,
67: never calls
68: .IR csh .
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.