1 .\" Copyright 1991 The Regents of the University of California.
2 .\" 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 6.4 (Berkeley) 4/30/91
34 .\" Converted for Linux, Mon Nov 29 14:45:38 1993, faith@cs.unc.edu
35 .\" Modified Sat May 18 20:37:44 1996 by Martin Schulze (joey@linux.de)
36 .\" Modified 7 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
38 .\" Japanese Version Copyright (c) 1997 Takashi Yoshino
39 .\" all rights reserved.
40 .\" Translated 1997-01-21, Takashi Yoshino <tyoshino@eng.toyo.ac.jp>
41 .\" Modified 2007-05-03, Akihiro MOTOKI
42 .\" Modified 2008-11-09, Akihiro MOTOKI, LDP v3.13
44 .TH POPEN 3 2010-02-03 "GNU" "Linux Programmer's Manual"
46 .\"O popen, pclose \- pipe stream to or from a process
48 popen, pclose \- プロセスとの入力/出力用のパイプ・ストリーム
54 .BI "FILE *popen(const char *" command ", const char *" type );
56 .BI "int pclose(FILE *" stream );
60 .\"O Feature Test Macro Requirements for glibc (see
61 .\"O .BR feature_test_macros (7)):
63 .RB ( feature_test_macros (7)
71 _POSIX_C_SOURCE\ >=\ 2 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE
78 .\"O function opens a process by creating a pipe, forking, and invoking the
80 .\"O Since a pipe is by definition unidirectional, the
82 .\"O argument may specify only reading or writing, not both; the resulting
83 .\"O stream is correspondingly read-only or write-only.
85 関数は、プロセスをオープンする。具体的には、
86 パイプを生成し、フォークを行い、シェルを起動する。
87 定義から分かるように、パイプは一方向なので、
89 引き数には読み込みか書き込みのどちらか一方だけを指定できる
91 生成されるストリームは、この指定に対応して、読み取り専用または
96 .\"O argument is a pointer to a null-terminated string containing a shell
98 .\"O This command is passed to
102 .\"O flag; interpretation, if any, is performed by the shell.
105 .\"O argument is a pointer to a null-terminated string which must contain
106 .\"O either the letter \(aqr\(aq for reading or the letter \(aqw\(aq for writing.
109 NULL 終端された文字列へのポインタである。
115 コマンドの解釈は (もし必要ならば) シェルによって行われる。
117 引き数は、NULL 終端された文字列へのポインタで、
118 読み込みを示す文字 \(aqr\(aq か、書き込みを示す文字 \(aqw\(aq の
120 .\"O Since glibc 2.9,
121 .\"O this argument can additionally include the letter \(aqe\(aq,
122 .\"O which causes the close-on-exec flag
123 .\"O .RB ( FD_CLOEXEC )
124 .\"O to be set on the underlying file descriptor;
125 .\"O see the description of the
129 .\"O for reasons why this may be useful.
130 glibc 2.9 以降では、この引き数に文字 \(aqe\(aq を追加で指定できる。
142 .\"O The return value from
144 .\"O is a normal standard I/O stream in all respects save that it must be closed
150 からの返り値は、通常の標準 I/O ストリームと同じであるが、
155 .\"O Writing to such a stream writes to the standard input of the command; the
156 .\"O command's standard output is the same as that of the process that called
158 .\"O unless this is altered by the command itself.
159 .\"O Conversely, reading from a
160 .\"O "popened" stream reads the command's standard output, and the command's
161 .\"O standard input is the same as that of the process that called
163 このストリームへ書き込んだ結果はコマンドの標準入力に書き込まれる。
165 コマンドそのものが置き換わってしまわない限り、
167 を呼んだプロセスの標準出力と同じことになる。
170 によって開かれた) ストリームからの読み込みは、
171 そのコマンドの標準出力を読み込むことになる。
176 .\"O Note that output
178 .\"O streams are fully buffered by default.
181 の出力ストリームは完全にバッファリングされることに注意しよう。
185 .\"O function waits for the associated process to terminate and returns the exit
186 .\"O status of the command as returned by
189 関数は、(パイプに) 関連づけられたプロセスが終了するのを待ち、
191 によって返されたコマンドの終了状態を返す。
192 .\"O .SH "RETURN VALUE"
196 .\"O function returns NULL if the
200 .\"O calls fail, or if it cannot allocate memory.
207 メモリ割り当てができなかった場合、 NULL を返す。
211 .\"O function returns \-1 if
212 .\"O .\" These conditions actually give undefined results, so I commented
215 .\"O .\" is not associated with a "popen()ed" command, if
217 .\"O .\" already "pclose()d", or if
219 .\"O returns an error, or some other error is detected.
223 がエラーを返したり、何か他のエラーが見つかった場合、
229 .\"O function does not set
231 .\"O if memory allocation fails.
232 .\"O If the underlying
238 .\"O is set appropriately.
241 .\"O argument is invalid, and this condition is detected,
259 が無効であり、この状態が検知された場合には、
267 .\"O cannot obtain the child status,
272 が、子プロセスの状態を取得できなかった場合、
277 .\"O .SH "CONFORMING TO"
281 .\"O The \(aqe\(aq value for
283 .\"O is a Linux extension.
285 に指定できる \(aqe\(aq は Linux での拡張である。
288 .\"O Since the standard input of a command opened for reading shares its seek
289 .\"O offset with the process that called
291 .\"O if the original process has done a buffered read, the command's input
292 .\"O position may not be as expected.
293 .\"O Similarly, the output from a command
294 .\"O opened for writing may become intermingled with that of the original
296 .\"O The latter can be avoided by calling
300 読み込みのために開かれたコマンドの標準入力は
302 を呼んだプロセスと一緒に、その読み取り位置を共有する。
303 そのため、もとのプロセスがバッファリングされた読み取りを終了したら、
304 そのコマンドの入力位置は予想されたものには
306 同様に、書き込みのために開かれたコマンドからの出力は、
307 もとのプロセスの出力と混ざり合うことになるかもしれない。
314 .\"O Failure to execute the shell is indistinguishable from the shell's failure
315 .\"O to execute command, or an immediate exit of the command.
316 .\"O The only hint is an exit status of 127.
319 コマンドがすぐに終了してしまったことと、区別がつかない。
320 唯一のヒントは終了状態が 127 になることである。
324 .\"O .\" .BR popen ()
326 .\"O .\" .BR pclose ()
327 .\"O .\" function appeared in Version 7 AT&T UNIX.
331 .\" 関数は AT&T UNIX の Version 7 から導入された。