我通过Laravel控制台安排了一个cronjob。它正在工作,并在每一分钟给出结果。但我尝试使用sendOutputTo
和appendOutputTo
方法将输出写入文件。但这不是写入文件。我的文件有写权限。
以下是我的代码:
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";
}
答案 0 :(得分:1)
解决了这个问题。改变了路径
$filePath = base_path() . "\cron\CleanSession.txt";
至$filePath = base_path() . "/cron/CleanSession.txt";