问题
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