【问题标题】:Laravel command exec outputLaravel 命令执行输出
【发布时间】:2020-05-19 10:51:28
【问题描述】:

我正在尝试制作将执行非结束脚本的工匠命令(更准确地说,它是一个 gulp watch 命令)。是否可以实时向控制台输出内容而不等待脚本结束?

exec($basedir . "test.sh", $output);

foreach ($output as $item) {
    $this->info($item);
}

test.sh 看起来像这样(为了简洁而缩短):

echo "something"
echo "something else"

gulp watch

由于命令实际上并没有结束,我无法检索在其中运行的两个回声。有办法吗?

【问题讨论】:

    标签: php laravel bash shell laravel-artisan


    【解决方案1】:

    我通过以下方式解决了这个问题:

    while (@ ob_end_flush()) ; // end all output buffers if any
    
    // this section streams output to terminal 
    $proc = popen($basedir . "test.sh", 'r');
    while (!feof($proc)) {
        $this->info(fread($proc, 4096));
        @ flush();
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-11
      • 2017-10-19
      • 2015-08-27
      • 1970-01-01
      • 2021-11-07
      • 2018-01-16
      • 1970-01-01
      • 2019-10-15
      相关资源
      最近更新 更多