PHP 执行 Shell 命令

时间:2022-04-29
本文章向大家介绍PHP 执行 Shell 命令,主要内容包括exec()、shell_exec()、system()、反引号、其他、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

主要有 exec() shell_exec() system()

exec()

string exec ( string $command [, array $output [, int $return_var ]] )

返回最后一条结果。

如果使用了 output 参数,shell 命令的每行结果会填充到该数组中。

shell_exec()

string shell_exec(string $cmd)

字符串 形式返回执行的全部结果。

system()

string system(string $command [, int $return_value])

输出全部结果。

成功则返回命令输出的最后一行, 失败则返回 FALSE

反引号

反引号不能在双引号字符串中使用。

echo `ls`;

其他

请查看:http://php.net/manual/zh/ref.exec.php