From 6cd0feaaceadd6b0664a6378c0930c55aef0c00f Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Thu, 8 Jul 2021 10:24:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=92=A4=E9=94=80spawn=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index 23fc0941..fbccceaf 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -211,17 +211,18 @@ export default class CronService { cmdStr = `${cmdStr} now`; } - const cp = exec(cmdStr, (err, stdout, stderr) => { + const cp = spawn(cmdStr, { shell: true, detached: true }); + this.cronDb.update( + { _id }, + { $set: { status: CrontabStatus.running, pid: cp.pid } }, + ); + cp.on('close', (code) => { this.cronDb.update( { _id }, { $set: { status: CrontabStatus.idle }, $unset: { pid: true } }, ); resolve(); }); - this.cronDb.update( - { _id }, - { $set: { status: CrontabStatus.running, pid: cp.pid } }, - ); }); }