共計 871 個字符,預計需要花費 3 分鐘才能閱讀完成。
php 中的命令執行函數有 System、Exec 和 Passthru 幾種
1.System 函數
System 函數作用:
php 中 System 函數的作用是用于執行 command 參數所指定的命令,且打印全部的輸出值。
System 函數語法:
system (string $command , int &$return_var = ?) : string
參數:
command:需要執行的命令。
return_var:外部命令執行后的返回狀態將會被設置到此變量中。
System 函數使用方法:
$v = system('netstat -tnlp',$shell_return);
var_dump($shell_return);
var_dump($v);
2.Exec 函數
Exec 函數作用:
php 中 Exec 函數的作用是用于執行 command 參數所指定的命令,且不打印任何內容。
Exec 函數語法:
exec (string $command , array &$output = ? , int &$return_var = ?) : string
Exec 函數使用方法:
$out = ['a'=>'apple','b'=>'banana','c'=>'cat','d'=>'dog'];
$shell_return=null;
$v = exec('netstat -tnlp',$out,$shell_return);
print_r($out);
var_dump($shell_return);
var_dump($v);
3.Passthru 函數
Passthru 函數作用:
php 中 Passthru 函數的作用是用于執行外部程序并且顯示原始輸出。
Passthru 函數語法:
passthru (string $command , int &$return_var = ?) : void
參數:
command:需要執行的命令。
return_var:Unix 命令的返回狀態會被記錄到此參數。
Passthru 函數使用方法:
passthru('ls', $return_val);
echo 'Exit code of $return_val\n';
丸趣 TV 網 – 提供最優質的資源集合!