Artisan输出缓冲区不包含所有输出 [英] Artisan output buffer does not contain all output

查看:44
本文介绍了Artisan输出缓冲区不包含所有输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码重定向路线中工匠命令的输出.

I'm using the following code to redirect the output of an artisan command within a route.

use Symfony\Component\Console\Output\BufferedOutput;

Route::get('/restart', function()
{
    $output = new BufferedOutput;
    Artisan::call('remote:restart', array(), $output);
    return $output->fetch();
});

这适用于大多数情况.但是,如果在命令中使用SSH组件在远程服务器上运行某些任务,则上述代码将忽略SSH::into()->run()的输出.

This works for most cases. However if within the command I use the SSH component to run some tasks on a remote server, the output resulting from SSH::into()->run() will be disregarded by the above code.

如果我手动运行artisan命令,则会得到以下输出:

If I run the artisan command manually, I get the following output:

start
[root@remote-host] (xxxx) Stopping php-fpm: 
[root@remote-host] (xxxx) [  OK  ]
[root@remote-host] (xxxx) Starting php-fpm: 
[root@remote-host] (xxxx) [  OK  ]
[root@remote-host] (xxxx) Stopping nginx: 
[root@remote-host] (xxxx) [  OK  ]
[root@remote-host] (xxxx) Starting nginx: 
[root@remote-host] (xxxx) [  OK  ]
end

但是$ output-> fetch()仅返回:

But $output->fetch() only returns:

start end

推荐答案

您需要在其上设置输出接口:

You need to set the output interface on it:

use Symfony\Component\Console\Output\BufferedOutput;

Route::get('/test', function()
{
    $output = new BufferedOutput;

    SSH::setOutput($output);

    SSH::run('ls -la');

    return $output->fetch();
});

这篇关于Artisan输出缓冲区不包含所有输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆