Log into file when executed by "Run"

pull/106/head
Pascal 2019-08-04 18:55:38 +02:00
parent 7bf1135a81
commit 8692ae8e20
1 changed files with 6 additions and 6 deletions

View File

@ -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");
@ -77,9 +77,9 @@ 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 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]});
});
};