Last active
June 6, 2025 15:12
-
-
Save Shelob9/bfaa00225097505bb6c06893051d1d6e to your computer and use it in GitHub Desktop.
Call one artisan command, from another command, echo or stream its output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the Stream version ! It saves my day :-)