PageRenderTime 1248ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/php/function.system.html

https://bitbucket.org/stillzhl/manuals
HTML | 143 lines | 117 code | 26 blank | 0 comment | 0 complexity | 695dc16db54b4d6cbcc32b431adec1d4 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. <title>Execute an external program and display the output</title>
  6. </head>
  7. <body><div class="manualnavbar" style="text-align: center;">
  8. <div class="prev" style="text-align: left; float: left;"><a href="function.shell-exec.html">shell_exec</a></div>
  9. <div class="next" style="text-align: right; float: right;"><a href="book.pthreads.html">pthreads</a></div>
  10. <div class="up"><a href="ref.exec.html">Program execution 函数</a></div>
  11. <div class="home"><a href="index.html">PHP Manual</a></div>
  12. </div><hr /><div id="function.system" class="refentry">
  13. <div class="refnamediv">
  14. <h1 class="refname">system</h1>
  15. <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">system</span> &mdash; <span class="dc-title">Execute an external program and display the output</span></p>
  16. </div>
  17. <div class="refsect1 description" id="refsect1-function.system-description">
  18. <h3 class="title">说明</h3>
  19. <div class="methodsynopsis dc-description">
  20. <span class="type">string</span> <span class="methodname"><strong>system</strong></span>
  21. ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$command</code></span>
  22. [, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$return_var</code></span>
  23. ] )</div>
  24. <p class="para rdfs-comment">
  25. <span class="function"><strong>system()</strong></span> is just like the C version of the
  26. function in that it executes the given
  27. <em><code class="parameter">command</code></em> and outputs the result.
  28. </p>
  29. <p class="para">
  30. The <span class="function"><strong>system()</strong></span> call also tries to automatically
  31. flush the web server&#039;s output buffer after each line of output if
  32. PHP is running as a server module.
  33. </p>
  34. <p class="para">
  35. If you need to execute a command and have all the data from the
  36. command passed directly back without any interference, use the
  37. <span class="function"><a href="function.passthru.html" class="function">passthru()</a></span> function.
  38. </p>
  39. </div>
  40. <div class="refsect1 parameters" id="refsect1-function.system-parameters">
  41. <h3 class="title">参数</h3>
  42. <p class="para">
  43. <dl>
  44. <dt>
  45. <span class="term"><em><code class="parameter">command</code></em></span>
  46. <dd>
  47. <p class="para">
  48. The command that will be executed.
  49. </p>
  50. </dd>
  51. </dt>
  52. <dt>
  53. <span class="term"><em><code class="parameter">return_var</code></em></span>
  54. <dd>
  55. <p class="para">
  56. If the <em><code class="parameter">return_var</code></em> argument is present, then the
  57. return status of the executed command will be written to this
  58. variable.
  59. </p>
  60. </dd>
  61. </dt>
  62. </dl>
  63. </p>
  64. </div>
  65. <div class="refsect1 returnvalues" id="refsect1-function.system-returnvalues">
  66. <h3 class="title">返回值</h3>
  67. <p class="para">
  68. Returns the last line of the command output on success, and <strong><code>FALSE</code></strong>
  69. on failure.
  70. </p>
  71. </div>
  72. <div class="refsect1 examples" id="refsect1-function.system-examples">
  73. <h3 class="title">范例</h3>
  74. <p class="para">
  75. <div class="example" id="example-3476">
  76. <p><strong>Example #1 <span class="function"><strong>system()</strong></span> example</strong></p>
  77. <div class="example-contents">
  78. <div class="phpcode"><code><span style="color: #000000">
  79. <span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;pre&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Outputs&nbsp;all&nbsp;the&nbsp;result&nbsp;of&nbsp;shellcommand&nbsp;"ls",&nbsp;and&nbsp;returns<br />//&nbsp;the&nbsp;last&nbsp;output&nbsp;line&nbsp;into&nbsp;$last_line.&nbsp;Stores&nbsp;the&nbsp;return&nbsp;value<br />//&nbsp;of&nbsp;the&nbsp;shell&nbsp;command&nbsp;in&nbsp;$retval.<br /></span><span style="color: #0000BB">$last_line&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">system</span><span style="color: #007700">(</span><span style="color: #DD0000">'ls'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$retval</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Printing&nbsp;additional&nbsp;info<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'<br />&lt;/pre&gt;<br />&lt;hr&nbsp;/&gt;Last&nbsp;line&nbsp;of&nbsp;the&nbsp;output:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$last_line&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'<br />&lt;hr&nbsp;/&gt;Return&nbsp;value:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$retval</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
  80. </span>
  81. </code></div>
  82. </div>
  83. </div>
  84. </p>
  85. </div>
  86. <div class="refsect1 notes" id="refsect1-function.system-notes">
  87. <h3 class="title">注释</h3>
  88. <div class="warning"><strong class="warning">Warning</strong><p class="para">当用户提供的数据传入此函数使用
  89. <span class="function"><a href="function.escapeshellarg.html" class="function">escapeshellarg()</a></span> <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span>
  90. 来确保用户欺骗系统从而执行任意命令</p></div>
  91. <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">如何程序使用此函数启动为了能保持在后台运行此程序必须将输出重定向到文件或其它输出流否则会导致
  92. PHP 挂起直至程序执行结束</p></p></blockquote>
  93. <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"><a href="features.safe-mode.html" class="link">安全模式</a> 启用时可仅可用
  94. <a href="ini.sect.safe-mode.html#ini.safe-mode-exec-dir" class="link">safe_mode_exec_dir</a> 执行文件实际上现在不允许在到可执行的路径中存在 <em>..</em> 组件</span></p></blockquote>
  95. <div class="warning"><strong class="warning">Warning</strong><p class="simpara"><a href="features.safe-mode.html" class="link">安全模式</a> 启用时命令字符串会被
  96. <span class="function"><a href="function.escapeshellcmd.html" class="function">escapeshellcmd()</a></span> 转换因此<em>echo y | echo x</em> 会变成
  97. <em>echo y \| echo x</em></p></div>
  98. </div>
  99. <div class="refsect1 seealso" id="refsect1-function.system-seealso">
  100. <h3 class="title">参见</h3>
  101. <p class="para">
  102. <ul class="simplelist">
  103. <li class="member"> <span class="function"><a href="function.exec.html" class="function" rel="rdfs-seeAlso">exec()</a> - Execute an external program</span></li>
  104. <li class="member"> <span class="function"><a href="function.passthru.html" class="function" rel="rdfs-seeAlso">passthru()</a> - Execute an external program and display raw output</span></li>
  105. <li class="member"> <span class="function"><a href="function.popen.html" class="function" rel="rdfs-seeAlso">popen()</a> - 打开进程文件指针</span></li>
  106. <li class="member"> <span class="function"><a href="function.escapeshellcmd.html" class="function" rel="rdfs-seeAlso">escapeshellcmd()</a> - Escape shell metacharacters</span></li>
  107. <li class="member"> <span class="function"><a href="function.pcntl-exec.html" class="function" rel="rdfs-seeAlso">pcntl_exec()</a> - 在当前进程空间执行指定程序</span></li>
  108. <li class="member"><a href="language.operators.execution.html" class="link">backtick operator</a></li>
  109. </ul>
  110. </p>
  111. </div>
  112. </div><hr /><div class="manualnavbar" style="text-align: center;">
  113. <div class="prev" style="text-align: left; float: left;"><a href="function.shell-exec.html">shell_exec</a></div>
  114. <div class="next" style="text-align: right; float: right;"><a href="book.pthreads.html">pthreads</a></div>
  115. <div class="up"><a href="ref.exec.html">Program execution 函数</a></div>
  116. <div class="home"><a href="index.html">PHP Manual</a></div>
  117. </div></body></html>