Laravel命令执行输出

问题描述 投票:0回答:1

我正在尝试制作能够执行不间断脚本的工匠命令(更确切地说,这是一个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 artisan
1个回答
0
投票

我已经通过以下操作解决了它:

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();
}
© www.soinside.com 2019 - 2024. All rights reserved.