在Laravel中获取控制台输出 [英] Getting console output in Laravel
本文介绍了在Laravel中获取控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当需要时,我还需要捕获控制台命令的输出,该命令也将通过电子邮件发送.我该怎么办?
I need to capture the output of a console command to be sent by email as well when requested. How can I do this?
如何获取以下$this->info()
调用生成的输出?
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']);
推荐答案
决定仅将$this->info()
调用替换为简单的echo命令和输出缓冲区控制.在控制台中看起来足够好,并且可以捕获请求通过电子邮件发送的数据.
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.
示例:
$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();
}
这篇关于在Laravel中获取控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文