Getting console output in Laravel

喜你入骨 提交于 2019-12-11 17:01:53

问题


I need to capture the output of a console command to be sent by email as well when requested. How can I do this?

How do I get the output generated from the following $this->info() calls?

$r = processData();

$this->info("\nSubmitted data:");
$this->info("SubmissionId: " . $r['submission_id']);
$this->info("Status: " . $r['status']);

回答1:


Decided to just replace the $this->info() calls with a simple echo command and output buffer control. Looks good enough in the console and catches the data requested for emailing.

Example:

$r = processData();

if ($this->option('email-results'))
    ob_start();

echo "\nSubmitted data:";
echo "\nSubmissionId: " . $r['submission_id'];
echo "\nStatus: " . $r['status'];

if ($this->option('email-results')) {
    mail(
        $this->option('email-results'),
        'Results on ' . $start_time->toDateTimeString(),
        ob_get_contents()
    );

    ob_end_flush();
}


来源:https://stackoverflow.com/questions/26936315/getting-console-output-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!