phplaravellaravel-4

How to save/redirect output from Laravel Artisan command?


I'm using Artisan::call() in one of my routes and would like to save the command output to a variable.

Is there any way to capture the STDOUT and STDERR generated by the artisan command?


Solution

  • This is a way:

    use Symfony\Component\Console\Output\BufferedOutput;
    
    Route::get('/test', function()
    {
        $output = new BufferedOutput;
    
        Artisan::call('list', array(), $output);
    
        return $output->fetch();
    });