node-cross-spawn icon indicating copy to clipboard operation
node-cross-spawn copied to clipboard

Stop Child Process on SIGINT

Open meilechwieder opened this issue 4 years ago • 1 comments

When I press ctrl+c on the termianl while I run a script that uses croos-spawn, it does not stop the child process

Notice I use spawn.sync. But even without sync, It doesn't stop the child process

const spawn = require('cross-spawn');
process.on('SIGINT', function () {
  console.log('Caught interrupt signal');
  process.kill(ls.pid);
  process.exit()
});
var rl = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.on('SIGINT', function () {
  process.emit('SIGINT');
});
ls = spawn.sync('expo', ['publish'], { stdio: 'inherit' });

meilechwieder avatar Aug 26 '21 19:08 meilechwieder

I wonder if this is the same problem that nodemon had to deal with in https://github.com/remy/nodemon/issues/1025.

Specifically, using child_process.fork instead of child_process.spawn for node executables.

I'm using npm to run a package.json#script, which in turn uses nodemon with cross-env to launch the webpack cli. Something in that chain is leaving the webpack dev server running... I think this might be it?

cinderblock avatar Aug 29 '21 20:08 cinderblock