如何保存/重定向Laravel Artisan命令的输出? [英] How to save/redirect output from Laravel Artisan command?

查看:121
本文介绍了如何保存/重定向Laravel Artisan命令的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一条路线中使用了Artisan::call(),并且希望将命令输出保存到变量中.

I'm using Artisan::call() in one of my routes and would like to save the command output to a variable.

有什么方法可以捕获artisan命令生成的STDOUT和STDERR吗?

Is there any way to capture the STDOUT and STDERR generated by the artisan command?

推荐答案

这是一种方法:

use Symfony\Component\Console\Output\BufferedOutput;

Route::get('/test', function()
{
    $output = new BufferedOutput;

    Artisan::call('list', array(), $output);

    return $output->fetch();
});

这篇关于如何保存/重定向Laravel Artisan命令的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆