system
执行外部程序,并且显示输出
&reftitle.description;
stringfalsesystem
stringcommand
intresult_code&null;
同 C 版本的 system 函数一样,本函数执行
command 参数所指定的命令,并且输出执行结果。
如果 PHP 运行在服务器模块中,system
函数还会尝试在每行输出完毕之后,自动刷新 web 服务器的输出缓存。
如果要获取一个命令未经任何处理的原始输出,请使用
passthru 函数。
&reftitle.parameters;
command
要执行的命令。
result_code
如果提供 result_code
参数,则外部命令执行后的返回状态将会被设置到此变量中。
&reftitle.returnvalues;
成功则返回命令输出的最后一行,失败则返回 &false;
&reftitle.examples;
system 示例
';
// 输出 shell 命令 "ls" 的返回结果
// 并且将输出的最后一样内容返回到 $last_line。
// 将命令的返回值保存到 $retval。
$last_line = system('ls', $retval);
// 打印更多信息
echo '
Last line of the output: ' . $last_line . '
Return value: ' . $retval;
?>
]]>
&reftitle.notes;
&warn.escapeshell;
¬e.exec-bg;
&reftitle.seealso;
exec
passthru
popen
escapeshellcmd
pcntl_exec
执行运算符