我有一个Node脚本,它以这种方式调用外部程序(PluginManager.exe):
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需要8秒才能执行。我的问题是,在子进程退出之后,Node脚本还会继续运行10秒。我知道PluginManager.exe何时结束,因为我可以看到它从Windows进程列表中消失。
是什么使Node进程运行这么长时间,以及如何确保它在子进程退出时立即退出?
发布于 2018-04-13 16:42:52
也许它是在等待输入,并在10秒后超时?
尝试使用.end()关闭stdin,如stdin中提到的
(在这种用法中,您将需要execFile的原始返回值,所以不要像https://stackoverflow.com/a/30883005/1105015那样promisify )
例如:
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();发布于 2018-04-13 16:10:11
您是否尝试过将killSignal选项设置为更痛苦的东西?
const process = execFile('PluginManager.exe', ['/install'], {killSignal: 'SIGKILL'});https://stackoverflow.com/questions/49656252
复制相似问题