在Laravel控制台中发送输出

时间:2016-03-01 10:45:38

标签: laravel laravel-5 laravel-5.1 laravel-5.2

我通过Laravel控制台安排了一个cronjob。它正在工作,并在每一分钟给出结果。但我尝试使用sendOutputToappendOutputTo方法将输出写入文件。但这不是写入文件。我的文件有写权限。

以下是我的代码:

Kernel.php

protected function schedule(Schedule $schedule) {

  $filePath = base_path() . "\cron\CleanSession.txt";

  $schedule->command('cleansession')
           ->everyMinute()
           ->sendOutputTo($filePath);
}

session.php文件

public function handle() {

        $this->info('Display this on the screen');
        $onlineCodeObj = new OnlineCode();
        if ($onlineCodeObj->cleanSession()) {
            echo "SESSION CLEANED : echo" . "\n";
            return "SESSION CLEANED: return" . "\n";
        }
         echo "SESSION CLEANED : echo2" . "\n";
         return "SESSION CLEANED: return2" . "\n";
    }

1 个答案:

答案 0 :(得分:1)

解决了这个问题。改变了路径

$filePath = base_path() . "\cron\CleanSession.txt";$filePath = base_path() . "/cron/CleanSession.txt";