child_process 6.9.1版本 stdout 被占用导致 回调迟迟没有退出

来源:互联网 发布:淘宝客推广计入销量吗 编辑:程序博客网 时间:2024/04/28 03:39

The 'close' event is emitted when the stdio streams of a child process have been closed. This is distinct from the 'exit' event, since multiple processes might share the same stdio streams.

这句话是说 stdio 关闭后才会触发close事件  


应用场景分析:child_process.exec调用了脚本a.sh,a.sh 调用脚本b.sh  b.sh 中 使用了  expect 命令 ,spawn命令启动了进程安装hadoop。


问题描述:安装结束,没有处罚close事件,stdio被占用,回调迟迟没有退出!


处理办法:通过exit事件 判断进程结束,在exit事件的回调中 通过错误码判断是否异常退出。

chboot.on("exit", function(code, signal) {    console.warn("TMP boot exit: " + code + ", " + signal);    chboot.stdin.end();    if (g_installStatus.bIsComplete == false) {        g_installStatus.bIsComplete = true;        g_installStatus['installRes'].status = true;        if (code == 0) {            g_installStatus['installRes'].detail = bout;        } else {            g_installStatus['installRes'].detail = berr;        }    }    setTimeout(function() {        g_isInstallUpdate = false;    }, 10*1000);});

原创粉丝点击