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); });