问题
I have tried the method described here but this doesn't work on my Laravel 5 installation.
use Symfony\Component\Console\Output\BufferedOutput;
Route::get('/test', function()
{
$output = new BufferedOutput;
Artisan::call('testCommand', array(), $output);
return $output->fetch();
});
My command;
public function fire()
{
$this->info('No output visible');
}
Any suggestions what I might do wrong? Or is it something that has changed in Laravel 5?
回答1:
I managed to get this to work using Artisan::output()
, which returns the output of the latest command.
Route::get('/test', function()
{
Artisan::call('testCommand', array());
return Artisan::output();
});
should do it for you.
回答2:
I did this
php artisan your:command >> output.txt
worked fine for me.
回答3:
I've had the same problem, replacing BufferedOutput with oldschool PHP made it work for me, perhaps it works for you too:
Route::get('/test', function()
{
ob_start();
Artisan::call('testCommand');
$output = ob_get_clean();
return $output;
});
回答4:
If you're working off the command line then you can pipe through the tee
command to write to a file and stdout
at the same time.
php artisan <command> | tee <filename>
来源:https://stackoverflow.com/questions/28662577/how-to-save-redirect-output-from-laravel-5-artisan-command