Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 922
Dave Avatar asked Nov 21 '13 02:11

Dave


2 Answers

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();
});
like image 132
Antonio Carlos Ribeiro Avatar answered Oct 21 '22 10:10

Antonio Carlos Ribeiro


When running a command from inside another command, here is how to get all the styling:

public function handle()
{
    Artisan::call('other:command', [], $this->getOutput());
}
like image 8
Vincent Mimoun-Prat Avatar answered Oct 21 '22 11:10

Vincent Mimoun-Prat