1 .\" $NetBSD: popen.3,v 1.20 2015/01/21 08:35:31 wiz Exp $
3 .\" Copyright (c) 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)popen.3 8.2 (Berkeley) 5/3/95
46 .Fn popen "const char *command" "const char *type"
48 .Fn popenve "const char *path" "char * const *argv" "char * const *envp" "const char *type"
50 .Fn pclose "FILE *stream"
56 a process by creating an IPC connection,
58 and invoking the shell.
61 was implemented with a unidirectional pipe;
62 hence many implementations of
66 argument to specify reading or writing, not both.
69 is now implemented using sockets, the
71 may request a bidirectional data flow.
74 argument is a pointer to a null-terminated string
81 for reading and writing.
82 In addition if the character
86 string, the file descriptor used internally is set to be closed on
91 argument is a pointer to a null-terminated string
92 containing a shell command line.
93 This command is passed to
97 flag; interpretation, if any, is performed by the shell.
101 function is similar to
103 but the first three arguments are passed
106 and there is no shell involved in the command invocation.
108 The return value from
114 stream in all respects
115 save that it must be closed with
119 Writing to such a stream
120 writes to the standard input of the command;
121 the command's standard output is the same as that of the process that called
123 unless this is altered by the command itself.
124 Conversely, reading from a
126 stream reads the command's standard output, and
127 the command's standard input is the same as that of the process that called
132 streams are fully buffered by default.
136 function waits for the associated process to terminate
137 and returns the exit status of the command
151 or if it cannot allocate memory, preserving
152 the errno from those functions.
159 is not associated with a
169 returns an error, preserving the errno returned by
199 Since the standard input of a command opened for reading
200 shares its seek offset with the process that called
202 if the original process has done a buffered read,
203 the command's input position may not be as expected.
204 Similarly, the output from a command opened for writing
205 may become intermingled with that of the original process.
206 The latter can be avoided by calling
211 Failure to execute the shell
212 is indistinguishable from the shell's failure to execute command,
213 or an immediate exit of the command.
214 The only hint is an exit status of 127.
226 function first appeared in