How to save/redirect output from Laravel 5 Artisan command?

浪子不回头ぞ 提交于 2019-12-23 07:50:04

问题


I have tried the method described here but this doesn't work on my Laravel 5 installation.

use Symfony\Component\Console\Output\BufferedOutput;

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

    Artisan::call('testCommand', array(), $output);

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

My command;

public function fire()
{
    $this->info('No output visible');
}

Any suggestions what I might do wrong? Or is it something that has changed in Laravel 5?


回答1:


I managed to get this to work using Artisan::output(), which returns the output of the latest command.

Route::get('/test', function()
{    
    Artisan::call('testCommand', array());

    return Artisan::output();
});

should do it for you.




回答2:


I did this

php artisan your:command >> output.txt

worked fine for me.




回答3:


I've had the same problem, replacing BufferedOutput with oldschool PHP made it work for me, perhaps it works for you too:

Route::get('/test', function()
{
    ob_start();
    Artisan::call('testCommand');
    $output = ob_get_clean();
    return $output;
});



回答4:


If you're working off the command line then you can pipe through the tee command to write to a file and stdout at the same time.

php artisan <command> | tee <filename>


来源:https://stackoverflow.com/questions/28662577/how-to-save-redirect-output-from-laravel-5-artisan-command

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