在Laravel中获取控制台输出

问题描述 投票:0回答:2

我还需要捕获控制台命令的输出,并在收到请求时通过电子邮件发送。我该怎么办?

如何获得以下$this->info()调用产生的输出?

$r = processData();

$this->info("\nSubmitted data:");
$this->info("SubmissionId: " . $r['submission_id']);
$this->info("Status: " . $r['status']);
php laravel laravel-4
2个回答
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();
}

0
投票

工匠方法可以帮助:

\Illuminate\Support\Facades\Artisan::output()
© www.soinside.com 2019 - 2024. All rights reserved.