Search code examples
phplaravellaravel-5laravel-artisan

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


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?


Solution

  • 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.