要在PHP中执行shell命令,可以使用exec()函数、shell_exec()函数或system()函数。
exec(command, output, return_var);
复制代码
示例:
exec('ls -l', $output, $return_var);
print_r($output); // 输出命令执行结果
echo $return_var; // 输出命令返回值
复制代码
$output = shell_exec(command);
复制代码
示例:
$output = shell_exec('ls -l');
echo $output; // 输出命令执行结果
复制代码
system(command, return_var);
复制代码
示例:
system('ls -l', $return_var);
echo $return_var; // 输出命令返回值
复制代码
注意:
(adsbygoogle = window.adsbygoogle || []).push({});