首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >child_process.execFile慢速退出

child_process.execFile慢速退出
EN

Stack Overflow用户
提问于 2018-04-04 16:42:31
回答 2查看 1.6K关注 0票数 10

我有一个Node脚本,它以这种方式调用外部程序(PluginManager.exe):

代码语言:javascript
复制
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进程运行这么长时间,以及如何确保它在子进程退出时立即退出?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-13 16:42:52

也许它是在等待输入,并在10秒后超时?

尝试使用.end()关闭stdin,如stdin中提到的

(在这种用法中,您将需要execFile的原始返回值,所以不要像https://stackoverflow.com/a/30883005/1105015那样promisify )

例如:

代码语言:javascript
复制
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();
票数 1
EN

Stack Overflow用户

发布于 2018-04-13 16:10:11

您是否尝试过将killSignal选项设置为更痛苦的东西?

代码语言:javascript
复制
const process = execFile('PluginManager.exe', ['/install'], {killSignal: 'SIGKILL'});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49656252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档