CakePHP 3重定向控制台输出到文件 [英] CakePHP 3 Redirect ConsoleOutput to File

查看:67
本文介绍了CakePHP 3重定向控制台输出到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将控制台输出从shell重定向到CakePHP 3中的文件

I am trying to redirect the console output from a shell to a file in CakePHP 3

我发现了CakePHP 2的一些片段,但是它们似乎并没有正在工作...

I found some snippets for CakePHP 2, however, they do not seem to be working...

这是我到目前为止的代码...

Here is the code I have so far...

public $rootLogsDirectory = ROOT . DS . 'tmp' . DS . 'logs';
public $outputName;

public function __construct($stdout = null, $stderr = null, $stdin = null) {

    if(!is_dir($this->rootLogsDirectory)) {

        mkdir($this->rootLogsDirectory);
    }

    $this->outputName = tempnam($this->rootLogsDirectory, 'cronjobs');

    $stdout = new ConsoleOutput('file://' . $this->outputName . '.out');
    $stderr = new ConsoleOutput('file://' . $this->outputName . '.err');

    $ioNew = new ConsoleIo($stdout, $stderr);

    $ioNew->out('test');

    parent::__construct($ioNew);
}

但是, $ this-> out('你好世界')未被写入文件...

However, $this->out('hello world') is not being written to the file...

推荐答案

我错了使用语句,我将其更改为

I had the wrong use statement, I changed it from

use Cake\TestSuite\Stub\ConsoleOutput;

use Cake\Console\ConsoleOutput;

这篇关于CakePHP 3重定向控制台输出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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