How to save/redirect output from Laravel Artisan command?

后端 未结 3 1952
孤独总比滥情好
孤独总比滥情好 2020-12-05 19:53

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 STDER

3条回答
  •  悲哀的现实
    2020-12-05 20:31

    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();
    });
    

提交回复
热议问题