<?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.system.php',
    1 => 'system',
    2 => '执行外部程序，并且显示输出',
  ),
  'up' => 
  array (
    0 => 'ref.exec.php',
    1 => '程序执行函数',
  ),
  'prev' => 
  array (
    0 => 'function.shell-exec.php',
    1 => 'shell_exec',
  ),
  'next' => 
  array (
    0 => 'book.parallel.php',
    1 => 'parallel',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/exec/functions/system.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.system" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">system</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">system</span> &mdash; <span class="dc-title">执行外部程序，并且显示输出</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.system-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>system</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.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
    同 C 版本的 <span class="function"><strong>system()</strong></span> 函数一样，本函数执行
    <code class="parameter">command</code> 参数所指定的命令，并且输出执行结果。
  </p>
  <p class="para">
    如果 PHP 运行在服务器模块中，<span class="function"><strong>system()</strong></span>
    函数还会尝试在每行输出完毕之后，自动刷新 web 服务器的输出缓存。
  </p>
  <p class="para">
    如果要获取一个命令未经任何处理的原始输出，请使用
    <span class="function"><a href="function.passthru.php" class="function">passthru()</a></span> 函数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.system-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>
        参数，则外部命令执行后的返回状态将会被设置到此变量中。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.system-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    成功则返回命令输出的最后一行，失败则返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.system-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>system()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'&lt;pre&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// 输出 shell 命令 "ls" 的返回结果<br />// 并且将输出的最后一样内容返回到 $last_line。<br />// 将命令的返回值保存到 $retval。<br /></span><span style="color: #0000BB">$last_line </span><span style="color: #007700">= </span><span style="color: #0000BB">system</span><span style="color: #007700">(</span><span style="color: #DD0000">'ls'</span><span style="color: #007700">, </span><span style="color: #0000BB">$retval</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 打印更多信息<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'<br />&lt;/pre&gt;<br />&lt;hr /&gt;Last line of the output: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$last_line </span><span style="color: #007700">. </span><span style="color: #DD0000">'<br />&lt;hr /&gt;Return value: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$retval</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.system-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.system-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.passthru.php" class="function" rel="rdfs-seeAlso">passthru()</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><span class="function"><a href="function.pcntl-exec.php" class="function" rel="rdfs-seeAlso">pcntl_exec()</a> - 在当前进程空间执行指定程序</span></li>
    <li><a href="language.operators.execution.php" class="link">执行运算符</a></li>
   </ul>
  </p>
 </div>

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