php命令执行函数有哪些

54次阅读
没有评论

共计 871 个字符,预计需要花费 3 分钟才能阅读完成。

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

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-13发表,共计871字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)