我有一个名为MyCommand的命令,我从一个名为MyJob的作业中调用它。当从作业中调用时,我无法看到命令输出。但是,如果我直接从命令行运行命令,则可以看到命令输出。
MyCommand.php代码:
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MyCommand extends Command
{
protected $signature = 'mycommand:doit';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->info('Process started');
//Some process is done here
$this->info('Process completed');
}
}
MyJob.php 代码:
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Artisan;
class MyJob implements ShouldQueue
{
public function __construct()
{
}
public function handle()
{
Artisan::call('mycommand:doit');
}
}