Artisan output buffer does not contain all output

China☆狼群 提交于 2019-12-09 23:11:07

问题


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();
});

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.

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

But $output->fetch() only returns:

start end

回答1:


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();
});


来源:https://stackoverflow.com/questions/20113385/artisan-output-buffer-does-not-contain-all-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!