我正在使用以下代码重定向路线中的artisan命令的输出。
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()
产生的输出将被上述代码忽略。
如果我手动运行artisan命令,我会得到以下输出:
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()只返回:
start end
答案 0 :(得分:4)
您需要在其上设置输出接口:
use Symfony\Component\Console\Output\BufferedOutput;
Route::get('/test', function()
{
$output = new BufferedOutput;
SSH::setOutput($output);
SSH::run('ls -la');
return $output->fetch();
});