在Laravel中获取控制台输出

时间:2014-11-14 18:11:26

标签: php laravel laravel-4

我需要捕获控制台命令的输出,以便在请求时通过电子邮件发送。我怎么能这样做?

如何获取以下$this->info()来电产生的输出?

$r = processData();

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

2 个答案:

答案 0 :(得分:0)

决定用简单的echo命令和输出缓冲区控制来替换$this->info()调用。在控制台中看起来很好,并且可以捕获请求发送电子邮件的数据。

示例:

$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();
}

答案 1 :(得分:0)

Artisan方法可以帮助您

\Illuminate\Support\Facades\Artisan::output()