From 8692ae8e2031a23de390a0bf53223ba092ae76fa Mon Sep 17 00:00:00 2001 From: Pascal Date: Sun, 4 Aug 2019 18:55:38 +0200 Subject: [PATCH] Log into file when executed by "Run" --- crontab.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crontab.js b/crontab.js index c195d2b..a4b0280 100644 --- a/crontab.js +++ b/crontab.js @@ -13,8 +13,8 @@ if(process.env.CRON_PATH !== undefined) { db.loadDatabase(function (err) { if (err) throw err; // no hope, just terminate }); - -var exec = require('child_process').exec; +var childProcess = require('child_process'); +var exec = childProcess.exec; var fs = require('fs'); var cron_parser = require("cron-parser"); @@ -76,10 +76,10 @@ exports.get_crontab = function(_id, callback) { exports.runjob = function(_id, callback) { db.find({_id: _id}).exec(function(err, docs){ - var res = docs[0]; - exec(res.command, function(error, stdout, stderr){ - console.log(stdout); - }); + var res = docs[0]; + var output = fs.openSync(path.join(exports.log_folder, _id + ".log"), 'w'); + var output2 = fs.openSync(path.join(exports.log_folder, _id + ".log"), 'a'); + childProcess.spawn('sh', ['-c', res.command], {stdio: ['ignore', output, output2]}); }); };