-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Artisan::output() returns empty string #36379
Comments
The CommandFinished event seems to already have an $output = $event->output; |
Been digging into this one but can't figure out why it's not working on the CLI. It seems the output buffer is cleared somehow before the process has ended. |
@taylorotwell Before resorting to Optimal would be if |
@yoeriboven you can try to do the same thing the output method doet and check for a fetch method which you can call: /**
* Get the output for the last run command.
*
* @return string
*/
public function output()
{
return $this->lastOutput && method_exists($this->lastOutput, 'fetch')
? $this->lastOutput->fetch()
: '';
} |
Nvm, doesn't seems to be available |
@driesvints Yeah, tried that already... 😬 |
Probably because: // Illuminate\Console\Application
$this->lastOutput; // returns \Symfony\Component\Console\Output\BufferedOutput
// Illuminate\Console\Events\CommandFinished
$event->output; // returns \Symfony\Component\Console\Output\OutputInterface |
Yeah I just figured out that myself. I'm wondering why |
I'm not sure we have a great solution at the moment. Best advice I can give you right now is instead of scheduling the Artisan command directly schedule a callback which calls Artisan::call: $schedule->call(function () {
Artisan::call('inspire');
}); |
This should fix the problem: #36404 Will require updating your "artisan" file to use Illuminate\Console\BufferedConsoleOutput instead of just ConsoleOutput. |
Description:
I'm trying to write the output of (scheduled) commands to a log file.
I expect
Artisan::output()
to return the output. This only works when the command is called manually. This method returns an empty string when the command was called through the command line or scheduler.Artisan uses the
lastOutput
property for this. This property is set inArtisan::call()
.Running commands in the cli or through the scheduler doesn't call this command. These use the
run()
command.Steps To Reproduce:
Manually
CLI
Possible solution:
If possible, set the
lastOutput
property in therun()
method instead ofcall()
.The text was updated successfully, but these errors were encountered: