Search code examples
laravellaravel-artisan

How to get Artisan::call('command:name') output in a variable?


Is it possible to get $output as follows:

$output = Artisan::call('command:name');

I have tried many solutions in different posts but it didn't work on my Laravel 5.2.


Solution

  • You can call the output method on Artisan

    Artisan::call('command:name');
    $output = Artisan::output();
    

    Make sure you are using one of the available output methods like $this->line('output'); in the actual Artisan command. More info in the docs.