10

I have a Node script that calls an external program (PluginManager.exe) this way:

const util = require('util');
const execFile = util.promisify(require('child_process').execFile);

const process = execFile('PluginManager.exe', ['/install']);
process
  .then(({stdout, stderr}) => console.log('done', stdout, stderr))
  .catch(e => console.log(e));

PluginManager.exe takes 8 seconds to execute. My problem is that the Node script keeps running for another 10 more seconds after the child process has exited. I know when PluginManager.exe finishes because I can see it disappear from the Windows Task Manager Process List.

What keeps the Node process running for so long and what can I do to make sure it exits as soon as the child process exits?

Sylvain
  • 19,099
  • 23
  • 96
  • 145

2 Answers2

1

Maybe it's waiting on input and timing out after 10s?

Try closing stdin with .end() as mentioned in https://nodejs.org/api/child_process.html#child_process_subprocess_stdin

(in this usage, you'll need the original return value of execFile, so don't promisify, as per https://stackoverflow.com/a/30883005/1105015)

e.g.

const util = require('util');
const execFile = require('child_process').execFile;

const process = execFile(
  'PluginManager.exe', ['/install'], (e, stdout, stderr) => {
    if (e) {
      console.log(e);
    } else {
      console.log('done', stdout, stderr));
    }});
process.stdin.end();
Rob Starling
  • 3,868
  • 3
  • 23
  • 40
0

Have you tried by adding the killSignal option set to something a bit more aggresive?

const process = execFile('PluginManager.exe', ['/install'], {killSignal: 'SIGKILL'});
QuarK
  • 2,306
  • 1
  • 20
  • 24