php - Laravel 命令执行输出
问题描述
我正在尝试制作将执行非结束脚本的工匠命令(更准确地说,它是一个 gulp watch 命令)。是否可以实时向控制台输出内容而不等待脚本结束?
exec($basedir . "test.sh", $output);
foreach ($output as $item) {
$this->info($item);
}
test.sh
看起来像这样(为简洁起见缩短):
echo "something"
echo "something else"
gulp watch
由于命令实际上并未结束,因此我无法检索在其中运行的两个回声。有没有办法做到这一点?
解决方案
我通过执行以下操作解决了它:
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();
}
推荐阅读
- dart - Flutter:字符串编码不正确-flutter中的toString将“转换为â
- android - exifinterface 27.1.0 , animated-vector-drawable:27.1.1 , 所有 com.android.support 库必须使用完全相同的版本
- c - Flex - Yacc:未定义对“YY_CURRENT_BUFFER”的引用
- maven - Maven 发布:缺少开发者信息
- css - 在 CSS 中适当使用 BEM
- android - 制作一个具有多个视图的自定义视图作为具有圆角边框的子视图
- java - 按钮触发功能和意图同时进行。安卓
- r - 使用 seq 函数对数据帧进行采样
- python - 在相同形状的两个数据框之间查找更大的行
- .net - Docker-compose 没有设置环境变量