Syl*_*ain 10 windows child-process node.js
我有一个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));
Run Code Online (Sandbox Code Playgroud)
PluginManager.exe需要8秒才能执行.我的问题是,在子进程退出后,Node脚本会再运行10秒钟.我知道什么时候PluginManager.exe完成,因为我可以看到它从Windows任务管理器进程列表中消失.
是什么让Node进程运行了这么长时间,我该怎么做以确保它在子进程退出后立即退出?
也许它正在等待输入并在 10 秒后超时?
尝试使用https://nodejs.org/api/child_process.html#child_process_subprocess_stdin.end()中提到的方式关闭标准输入
(在这种用法中,您需要 的原始返回值execFile,所以不要承诺,按照/sf/answers/2161810381/)
例如
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();
Run Code Online (Sandbox Code Playgroud)