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?
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();
});
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With