<?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 => 'zh',
  ),
  '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' => 'zh',
    '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"><a href="function.exec.php" class="function">exec()</a></span> 函数类似，
    <span class="function"><strong>passthru()</strong></span> 函数
    也是用来执行外部命令（<code class="parameter">command</code>）的。
    当所执行的 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>，
    然后调用 pbmplus 程序输出 gif 文件，
    就可以从 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="function"><strong>passthru()</strong></span> 现在将抛出
       <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> - shell 元字符转义</span></li>
    <li><a href="language.operators.execution.php" class="link">执行运算符</a></li>
   </ul>
  </p>
 </div>

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