溫馨提示×

php命令執行函數有哪些

PHP
養魚的貓咪
227
2021-03-24 10:01:25
欄目: 編程語言

php命令執行函數有哪些

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';

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女