<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.exec.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.passthru.php',
    1 => 'passthru',
    2 => '外部プログラムを実行し、未整形の出力を表示する',
  ),
  'up' => 
  array (
    0 => 'ref.exec.php',
    1 => 'プログラム実行関数',
  ),
  'prev' => 
  array (
    0 => 'function.exec.php',
    1 => 'exec',
  ),
  'next' => 
  array (
    0 => 'function.proc-close.php',
    1 => 'proc_close',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/exec/functions/passthru.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.passthru" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">passthru</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">passthru</span> &mdash; <span class="dc-title">外部プログラムを実行し、未整形の出力を表示する</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.passthru-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>passthru</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$command</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter reference">&$result_code</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>passthru()</strong></span>関数は<span class="function"><a href="function.exec.php" class="function">exec()</a></span>関数と同様、
   <code class="parameter">command</code>を実行します。
   引数 <code class="parameter">return_code</code> を指定した場合、
   Unix コマンドのステータスで置換されます。
   この関数は Unix コマンドからの出力がバイナリデータであり、
   ブラウザーへ直接返す必要がある場合、<span class="function"><a href="function.exec.php" class="function">exec()</a></span>
   もしくは<span class="function"><a href="function.system.php" class="function">system()</a></span>の代わりに使用する必要があります。
   よく使うのは、直接画像ストリームを出力することができる pbmplus
   ユーティリティの様なものを実行する場合です。content-type を
   <code class="literal">image/gif</code> に設定して、gifを出力するpbmplus
   プログラムを呼び出すことにより、直接画像を出力する PHP スクリプトを作成
   することができます。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.passthru-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">command</code></dt>
     <dd>
      <p class="para">
       実行するコマンド
      </p>
     </dd>
    
    
     <dt><code class="parameter">result_code</code></dt>
     <dd>
      <p class="para">
       引数<code class="parameter">result_code</code>が存在する場合、
       Unix コマンドのステータスがこの変数に書かれます。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.passthru-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   成功した場合に <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> を、失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.passthru-errors">
  <h3 class="title">エラー / 例外</h3>
  <p class="para">
   <span class="function"><strong>passthru()</strong></span>
   が <code class="parameter">command</code>
   を実行できない場合、<strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> が発生します。
  </p>
  <p class="para">
   <code class="parameter">command</code>
   が空だったり、null バイトが含まれている場合、
   <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> がスローされます。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.passthru-changelog">
  <h3 class="title">変更履歴</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>バージョン</th>
      <th>説明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">command</code>
       が空だったり、null バイトが含まれている場合、
       <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> がスローされるようになりました。
       これより前のバージョンでは、
       <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> が発生し、<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返していました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 notes" id="refsect1-function.passthru-notes">
  <h3 class="title">注意</h3>
  <div class="warning"><strong class="warning">警告</strong><p class="para">ユーザーが入力したデータをこの関数に
渡すことを許可する場合、ユーザーが任意のコマンドを実行できるようシステムを欺くことが
できないように <span class="function"><a href="function.escapeshellarg.php" class="function">escapeshellarg()</a></span> または
<span class="function"><a href="function.escapeshellcmd.php" class="function">escapeshellcmd()</a></span> を適用する必要があります。</p></div>
  <blockquote class="note"><p><strong class="note">注意</strong>: <p class="para">プログラムがこの関数で始まる場合、
バックグラウンドで処理を続けさせるには、
プログラムの出力をファイルや別の出力ストリームにリダイレクトする必要があります。
そうしないと、プログラムが実行を終えるまで PHP はハングしてしまいます。</p></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.passthru-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.exec.php" class="function" rel="rdfs-seeAlso">exec()</a> - 外部プログラムを実行する</span></li>
    <li><span class="function"><a href="function.system.php" class="function" rel="rdfs-seeAlso">system()</a> - 外部プログラムを実行し、出力を表示する</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - プロセスへのファイルポインタをオープンする</span></li>
    <li><span class="function"><a href="function.escapeshellcmd.php" class="function" rel="rdfs-seeAlso">escapeshellcmd()</a> - シェルのメタ文字をエスケープする</span></li>
    <li><a href="language.operators.execution.php" class="link">バッククォート演算子</a></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>