1 .\" Copyright (c) 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)popen.3 8.2 (Berkeley) 5/3/95
33 .\" $FreeBSD: src/lib/libc/gen/popen.3,v 1.16 2003/06/08 10:01:51 charnier Exp $
49 .Fa "const char *command"
50 .Fa "const char *mode"
61 a process by creating a bidirectional pipe, forking,
62 and invoking the shell.
63 Any streams opened by previous
65 calls in the parent process are closed in the new child process.
68 was implemented with a unidirectional pipe;
69 hence, many implementations of
73 argument to specify reading or writing, not both.
76 is now implemented using a bidirectional pipe, the
78 argument may request a bidirectional data flow.
81 argument is a pointer to a null-terminated string
88 for reading and writing.
92 argument is a pointer to a null-terminated string
93 containing a shell command line.
94 This command is passed to
98 flag; interpretation, if any, is performed by the shell.
100 The return value from
104 stream in all respects,
105 save that it must be closed with
109 Writing to such a stream
110 writes to the standard input of the command;
111 the command's standard output is the same as that of the process that called
113 unless this is altered by the command itself.
114 Conversely, reading from a
116 stream reads the command's standard output, and
117 the command's standard input is the same as that of the process that called
122 streams are fully buffered, by default.
126 function waits for the associated process to terminate;
127 it returns the exit status of the command,
140 or if it cannot allocate memory.
147 is not associated with a
159 function does not reliably set
172 Since the standard input of a command opened for reading
173 shares its seek offset with the process that called
175 if the original process has done a buffered read,
176 the command's input position may not be as expected.
177 Similarly, the output from a command opened for writing
178 may become intermingled with that of the original process.
179 The latter can be avoided by calling
184 Failure to execute the shell
185 is indistinguishable from the shell's failure to execute command,
186 or an immediate exit of the command.
187 The only hint is an exit status of 127.
204 Bidirectional functionality was added in