将STDOUT(Bash)传递给PHP变量
问题描述:
I want to pass the stdout of a command in bash (ex. uptime
) to a PHP variable, let's say uptime
too.
How this can be done?
我想在bash中传递一个命令的stdout(例如 uptime code>)到 一个PHP变量,让我们说
uptime code>。
如何做到这一点? p>
div>
答
Use shell_exec
for returning the output of shell commands:
<?php
$output = shell_exec('uptime');
echo $output;
?>
Result:
18:17 up 12 days, 13:39, 3 users, load averages: 1.80 1.78 1.75