I am trying to kill child processes created by command npm.cmd (spawned using Node.js API) on Windows.
It executes something like npm.cmd run build. Using process.kill() seems to be able to end the npm.cmd command successfully, but not the Node.js processes created by the npm command.
let cp = spawn('npm.cmd', ['run', 'build']);
cp.on('exit', code => {
// It will log after 5 seconds.
// But Node.js process created by `npm run build` will not end.
console.log(`Exited with code ${code}.`);
});
setTimeout(() => cp.kill(), 5000);
I tried to replace process.kill() to something like spawn('taskkill', ['/f', '/t', '/pid', process.pid]) and it worked well. How can I achieve the same thing using Node.js API?
via vilicvane
No comments:
Post a Comment