Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active June 6, 2025 15:12
Show Gist options
  • Save Shelob9/bfaa00225097505bb6c06893051d1d6e to your computer and use it in GitHub Desktop.
Save Shelob9/bfaa00225097505bb6c06893051d1d6e to your computer and use it in GitHub Desktop.
Call one artisan command, from another command, echo or stream its output
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class Name extends Command
{
protected $signature = 'something';
protected $description = 'Calls other commands';
public function handle()
{
//Run command
Artisan::call('one', []);
//Echo command one output, after it's completed
$this->info(Artisan::output());
//Run another command
Artisan::call('two', ['id' => 2 ], $output);
//Echo command two output, after it's completed
$this->info(Artisan::output());
}
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\StreamOutput;
class Name extends Command
{
protected $signature = 'something';
protected $description = 'Calls other commands';
public function handle()
{
//Create a stream
$output = new StreamOutput(fopen('php://stdout', 'w'));
//Run commands, while streaming output as output happens
Artisan::call('one', [], $output);
Artisan::call('two', ['id' => 2 ], $output);
}
}
@Cyrille37
Copy link

Thanks for the Stream version ! It saves my day :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment