mirror of
https://github.com/php/doc-ja.git
synced 2026-04-24 16:38:16 +02:00
def02cf418
Cf. <https://github.com/php/doc-en/pull/289>. git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@352198 c90b9560-bf6c-de11-be94-00142212c4b1
157 lines
5.1 KiB
XML
157 lines
5.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 0c9c2dd669fe9395eaa73d487fbd160f9057429a Maintainer: hirokawa Status: ready -->
|
|
<!-- Credits: mumumu -->
|
|
<refentry xml:id="function.popen" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>popen</refname>
|
|
<refpurpose>プロセスへのファイルポインタをオープンする</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>resource</type><type>false</type></type><methodname>popen</methodname>
|
|
<methodparam><type>string</type><parameter>command</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>mode</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<parameter>command</parameter> で指定したコマンドのフォークによってできたプロセスへのパイプをオープンします。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>command</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
コマンド。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>mode</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
モード。読み取りを行う場合は <literal>'r'</literal> を。
|
|
書き込みを行う場合は <literal>'w'</literal> を指定します。
|
|
</para>
|
|
<para>
|
|
Windows では、<function>popen</function> はデフォルトでテキストモードになります。
|
|
つまり、パイプから <literal>\n</literal> 文字を読み込んだり、書き込んだりすると、
|
|
<literal>\r\n</literal> に変換されるということです。
|
|
この振る舞いを望まない場合は、
|
|
<parameter>mode</parameter> にバイナリモードを指定し、強制することが出来ます。
|
|
読み取りのバイナリモードは <literal>'rb'</literal> を。
|
|
書き込みのバイナリモードは<literal>'wb'</literal> をそれぞれ指定します。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
<function>fopen</function>
|
|
により返されたファイルポインタと同様のものを返しますが、
|
|
それは(読み書きのいずれか一方でのみ使われる)片方向ストリームであり、
|
|
<function>pclose</function>
|
|
によりクローズされなければならないところが異なります。
|
|
このポインタは、<function>fgets</function>、<function>fgetss</function>
|
|
および <function>fwrite</function> のいずれかで使うことができます。
|
|
モードが 'r' のときは、返されるファイルポインタは
|
|
そのコマンドの STDOUT と等しくなります。また、モードが
|
|
'w' のときは、返されるファイルポインタは
|
|
そのコマンドの STDIN と等しくなります。
|
|
</para>
|
|
<para>
|
|
エラーが発生した場合は &false; を返します。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>popen</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$handle = popen("/bin/ls", "r");
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
実行すべきコマンドが見つからない場合には、正常なリソースが返されます。
|
|
おかしなことと思われるかもしれませんが、これには意味があります。
|
|
これによってシェルから返されたエラーメッセージにアクセスすることができるのです。
|
|
<example>
|
|
<title><function>popen</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
error_reporting(E_ALL);
|
|
|
|
/* リダイレクトにより、標準エラー出力を取得します */
|
|
$handle = popen('/path/to/executable 2>&1', 'r');
|
|
echo "'$handle'; " . gettype($handle) . "\n";
|
|
$read = fread($handle, 2096);
|
|
echo $read;
|
|
pclose($handle);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
双方向(two-way)のサポートを求めているのなら、
|
|
<function>proc_open</function> を使用してください。
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pclose</function></member>
|
|
<member><function>fopen</function></member>
|
|
<member><function>proc_open</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|