【问题标题】:php- how to get shell_exec() output from linux terminal while executing the command? [duplicate]php- 执行命令时如何从 linux 终端获取 shell_exec() 输出? [复制]
【发布时间】:2013-05-30 12:16:20
【问题描述】:

我在我的 php 脚本中使用shell_exec() 运行一个 linux 命令。

$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 linux shell-exec


【解决方案1】:

试试 passthru 功能。输出直接显示。您可以使用这个小脚本对其进行测试:

<?php
passthru('tail -f /var/log/apache2/access.log');
?>

【讨论】:

  • hmm.. 为什么页面正在加载???......没有显示任何内容.. @lexmihaylov 我不想直接输出到网页中的任何方式。我想要 table 中的结果
  • 抱歉,我以为您在谈论的是 cli 脚本而不是 web 脚本。
  • 嗯。你能用 shell_exec($command.' > '.$filename.' 2>'.$filename.' &');然后定期使用 ajax 方法获取 $filename 中的内容,对其进行解析并对其进行处理?
  • 嘿..我不处理文件yaar..它是一个命令的输出,它给出了系统的统计信息。好 ? @lexmihaylov
【解决方案2】:

您可以使用popen,查看手册了解更多详情popen manual

【讨论】:

    猜你喜欢
    • 2011-05-21
    • 2019-01-06
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 2012-06-13
    • 2015-08-16
    相关资源
    最近更新 更多