如何从CakePHP Shell捕获输出

如何从CakePHP Shell捕获输出,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,有没有办法用CakePHP捕获shell的输出? 我编写了一些为CakePHP 2.x应用程序生成报告的shell。我能够在命令行上运行shell并查看输出,但是,现在我想通过电子邮件发送这些shell的结果 我曾考虑使用另一个shell作为包装器,然后使用$this->dispatchShell('shellname')捕获其输出,但它似乎只运行shell并将其输出转储到CLI 要将Shell输出到文件,请在Shell的构造函数中声明一个输出流。下面是一个示例,将标准输出作为CakePHP的T

有没有办法用CakePHP捕获shell的输出?

我编写了一些为CakePHP 2.x应用程序生成报告的shell。我能够在命令行上运行shell并查看输出,但是,现在我想通过电子邮件发送这些shell的结果


我曾考虑使用另一个shell作为包装器,然后使用
$this->dispatchShell('shellname')
捕获其输出,但它似乎只运行shell并将其输出转储到CLI

要将Shell输出到文件,请在Shell的构造函数中声明一个输出流。下面是一个示例,将标准输出作为CakePHP的
TMP
目录(通常是
app/TMP/
)中名为
shell.out
的文件上的日志文件:

<?php
class FooShell extends AppShell {

    public function __construct($stdout = null, $stderr = null, $stdin = null) {
        // This will cause all Shell outputs, eg. from $this->out(), to be written to
        // TMP.'shell.out'
        $stdout = new ConsoleOutput('file://'.TMP.'shell.out');

        // You can do the same for stderr too if you wish
        // $stderr = new ConsoleOutput('file://'.TMP.'shell.err');

        parent::__construct($stdout, $stderr, $stdin);
    }

    public function main() {
        // The following output will not be printed on your console
        // but be written to TMP.'shell.out'
        $this->out('Hello world');
    }
}

刚刚再次测试,它从报告shell的主方法而不是$this->out内容获取任何返回值。我在shell中使用CakePhp 1.3.6进行了尝试,但在第7行的/path/sitemap.php中找不到类“ConsoleOutput”。我认为ConsoleOutput是cakephp 2.0+?这很好,正是我想要的,但是你知道是否可以附加到文件中,而不是每次都覆盖它吗?