(PHP 4, PHP 5, PHP 7, PHP 8)
shell_exec — 通過(guò) shell 環(huán)境執行命令,并且將完整的輸出以字符串的方式返回。
$cmd
): string本函數同 執行操作符。
注意:
On Windows, the underlying pipe is opened in text mode which can cause the function to fail for binary output. Consider to use popen() instead for such cases.
cmd
要執行的命令。
命令執行的輸出。
如果執行過(guò)程中發(fā)生錯誤或者進(jìn)程不產(chǎn)生輸出,則返回 null
。
注意:
當進(jìn)程執行過(guò)程中發(fā)生錯誤,或者進(jìn)程不產(chǎn)生輸出的情況下,都會(huì )返回
null
, 所以,使用本函數無(wú)法通過(guò)返回值檢測進(jìn)程是否成功執行。 如果需要檢查進(jìn)程執行的退出碼,請使用 exec() 函數。
示例 #1 shell_exec() 例程
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>