我在我Artisan::call()的一个路由中使用,并希望将命令输出保存到变量.
有没有办法捕获artisan命令生成的STDOUT和STDERR?
我在Kernel课堂上有这个命令:
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('products:import')
->appendOutputTo(storage_path('logs/import.log'));
}
Run Code Online (Sandbox Code Playgroud)
该方法创建一个名为的文件import.log,其中包含我在导入产品时添加的日志记录,并且运行良好。但是我需要能够php artisan products:import直接运行并在不调用类中的schedule方法Kernel或使用php artisan schedule:run.
我也没有在文档中找到。我应该添加什么来php artisan products:import创建文件?
编辑:如果我运行php artisan schedule:run,日志文件会因为 被创建appendOutputTo(storage_path('logs/import.log'));,但如果我php artisan products:import直接运行,则不会创建日志文件。我需要知道我应该在php artisan products:import命令行中添加什么以使其在这种情况下也能正常工作。