(PHP 4, PHP 5, PHP 7, PHP 8)
shell_exec — 通過(guò) shell 環(huán)境執(zhí)行命令,并且將完整的輸出以字符串的方式返回。
$cmd
): string本函數(shù)同 執(zhí)行操作符。
注意:
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
要執(zhí)行的命令。
命令執(zhí)行的輸出。
如果執(zhí)行過(guò)程中發(fā)生錯(cuò)誤或者進(jìn)程不產(chǎn)生輸出,則返回 null
。
注意:
當(dāng)進(jìn)程執(zhí)行過(guò)程中發(fā)生錯(cuò)誤,或者進(jìn)程不產(chǎn)生輸出的情況下,都會(huì)返回
null
, 所以,使用本函數(shù)無(wú)法通過(guò)返回值檢測(cè)進(jìn)程是否成功執(zhí)行。 如果需要檢查進(jìn)程執(zhí)行的退出碼,請(qǐng)使用 exec() 函數(shù)。
示例 #1 shell_exec() 例程
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>