我正在嘗試制作 artisan 命令,它將執行一個無休止的腳本(更準確地說,它是一個 gulp watch 命令)。是否可以實時輸出一些東西到控制臺而不是等待腳本結束?exec($basedir . "test.sh", $output);foreach ($output as $item) { $this->info($item);}test.sh看起來像這樣(為簡潔起見縮短):echo "something"echo "something else"gulp watch由于命令實際上并未結束,因此我無法檢索其中運行的兩個回聲。有辦法嗎?
1 回答

米脂
TA貢獻1836條經驗 獲得超3個贊
我已經通過執行以下操作解決了它:
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();
}
- 1 回答
- 0 關注
- 158 瀏覽
添加回答
舉報
0/150
提交
取消