array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.shell-exec.php', 1 => 'shell_exec', ), 'up' => array ( 0 => 'ref.exec.php', 1 => '程序执行函数', ), 'prev' => array ( 0 => 'function.proc-terminate.php', 1 => 'proc_terminate', ), 'next' => array ( 0 => 'function.system.php', 1 => 'system', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/exec/functions/shell-exec.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
shell_exec — 通过 shell 执行命令并将完整的输出以字符串的方式返回
command
要执行的命令。
string 包含已执行命令的输出,如果无法建立管道,则为
false
,如果发生错误或者命令不产生输出则为 null
注意:
当进程执行过程中发生错误,或者进程不产生输出的情况下,都会返回
null
。使用本函数无法检测执行是否成功。当需要访问程序退出代码时,应使用 exec()。
无法建立管道时会产生 E_WARNING
级别的错误。
示例 #1 shell_exec() 示例
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>