mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-19 06:16:58 +08:00
150 lines
7.1 KiB
HTML
150 lines
7.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>执行一个外部程序</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.exec" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">exec</h1>
|
|
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">exec</span> — <span class="dc-title">执行一个外部程序</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.exec-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>exec</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$command</code></span>
|
|
[, <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$output</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$return_var</code></span>
|
|
]] ) : <span class="type">string</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
<span class="function"><strong>exec()</strong></span> 执行
|
|
<code class="parameter">command</code> 参数所指定的命令。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.exec-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">output</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
如果提供了 <code class="parameter">output</code> 参数,
|
|
那么会用命令执行的输出填充此数组,
|
|
每行输出填充数组中的一个元素。
|
|
数组中的数据不包含行尾的空白字符,例如 <em>\n</em> 字符。
|
|
请注意,如果数组中已经包含了部分元素,<span class="function"><strong>exec()</strong></span>
|
|
函数会在数组末尾追加内容。如果你不想在数组末尾进行追加,
|
|
请在传入 <span class="function"><strong>exec()</strong></span> 函数之前
|
|
对数组使用 <span class="function"><a href="unset.html" class="function">unset()</a></span> 函数进行重置。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">return_var</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
如果同时提供
|
|
<code class="parameter">output</code> 和
|
|
<code class="parameter">return_var</code> 参数,
|
|
命令执行后的返回状态会被写入到此变量。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.exec-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
命令执行结果的最后一行内容。
|
|
如果你需要获取未经处理的全部输出数据,
|
|
请使用 <span class="function"><a href="passthru.html" class="function">passthru()</a></span> 函数。
|
|
</p>
|
|
<p class="para">
|
|
如果想要获取命令的输出内容,
|
|
请确保使用 <code class="parameter">output</code> 参数。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.exec-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-4359">
|
|
<p><strong>Example #1 <span class="function"><strong>exec()</strong></span> 例程</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// 输出运行中的 php/httpd 进程的创建者用户名<br />// (在可以执行 "whoami" 命令的系统上)<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'whoami'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.exec-notes">
|
|
<h3 class="title">注释</h3>
|
|
<div class="warning"><strong class="warning">Warning</strong><p class="para">当用户提供的数据传入此函数,使用
|
|
<span class="function"><a href="escapeshellarg.html" class="function">escapeshellarg()</a></span> 或 <span class="function"><a href="escapeshellcmd.html" class="function">escapeshellcmd()</a></span>
|
|
来确保用户欺骗系统从而执行任意命令。</p></div>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">如何程序使用此函数启动,为了能保持在后台运行,此程序必须将输出重定向到文件或其它输出流。否则会导致
|
|
PHP 挂起,直至程序执行结束。</p></p></blockquote>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">On Windows <span class="function"><strong>exec()</strong></span>
|
|
will first start cmd.exe to launch the command. If you want to start an external program without starting cmd.exe
|
|
use <span class="function"><a href="proc_open.html" class="function">proc_open()</a></span> with the <code class="parameter">bypass_shell</code> option set.</p></p></blockquote>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"><a href="features.safe_mode.html" class="link">安全模式</a> 启用时,可仅可用
|
|
<a href="ini.sect.safe-mode.html#ini.safe-mode-exec-dir" class="link">safe_mode_exec_dir</a> 执行文件。实际上,现在不允许在到可执行的路径中存在 <em>..</em> 组件。</span></p></blockquote>
|
|
<div class="warning"><strong class="warning">Warning</strong><p class="simpara"><a href="features.safe_mode.html" class="link">安全模式</a> 启用时,命令字符串会被
|
|
<span class="function"><a href="escapeshellcmd.html" class="function">escapeshellcmd()</a></span> 转换。因此,<em>echo y | echo x</em> 会变成
|
|
<em>echo y \| echo x</em>。</p></div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.exec-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="system.html" class="function" rel="rdfs-seeAlso">system()</a> - 执行外部程序,并且显示输出</span></li>
|
|
<li class="member"><span class="function"><a href="passthru.html" class="function" rel="rdfs-seeAlso">passthru()</a> - 执行外部程序并且显示原始输出</span></li>
|
|
<li class="member"><span class="function"><a href="escapeshellcmd.html" class="function" rel="rdfs-seeAlso">escapeshellcmd()</a> - shell 元字符转义</span></li>
|
|
<li class="member"><span class="function"><a href="pcntl_exec.html" class="function" rel="rdfs-seeAlso">pcntl_exec()</a> - 在当前进程空间执行指定程序</span></li>
|
|
<li class="member"><a href="language.operators.execution.html" class="link">执行运算符</a></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |