php-如何在执行命令时从linux终端获取shell_exec()输出?
我在我的php脚本中运行一个linux命令shell_exec()
。php-如何在执行命令时从linux终端获取shell_exec()输出?
$output = shell_exec('/usr/bin/linux-command ');
After
执行命令我正在把值变成一个变量。没关系。
但是,这里我的linux命令会给出输出continuously in terminal
。
它会像这样..
$linux-command
123 456 789
789 456 123
123 456 789 .. //and so on..(by pressing 'Ctrl+c' only we can stop this.
对于每5秒,将显示一条线。如何每5秒检索一次该行。
我的页面正在被加载........因为它正在等待$output
。
有什么办法可以解决我的问题吗?
任何想法表示赞赏。谢谢你在前进
尝试中继功能。输出直接显示。你可以用这个小脚本来进行测试:
<?php
passthru('tail -f /var/log/apache2/access.log');
?>
哼。 。为什么页面正在加载??? ......没有显示任何内容.. @lexmihaylov 任何我不想直接输出到网页的方法。我想在**表** –
的结果对不起,我认为你是在谈论一个CLI脚本而不是一个Web脚本。 – lexmihaylov
嗯。你可以使用shell_exec($ command。'>'。$ filename。'2>'。$ filename。'&');并且在那之后只是用ajax方法获得$ filename的内容,解析它并对它做些什么? – lexmihaylov
见http://*.com/questions/9791875/how-to-run-shell-script-with-live-feedback-from-php – devnull