我有javascript代码,运行exec,类似
exec('binary with argument', function(error, stdout,stderr)
{
// Calls a callback function if error is encountered
}
我还想使用该二进制文件的退出状态发送到上面的回调函数。通常的做法是
child.on("exit", function (code) {
console.log("exit:", code)
})
如何在exec错误处理程序中集成上面的exit实用程序,以便捕获返回错误代码并将其传递给回调函数?
答案 0 :(得分:2)
我需要二进制文件的退出状态,以便我可以将其返回给第一个代码段中的用户定义的回调。
根据the docs,您不需要倾听exit
事件来执行此操作:
回调获取参数
(error, stdout, stderr)
。成功的话error
将为null
。如果出错,error
将是一个实例Error
和error.code
将成为孩子的退出代码 进程,error.signal
将被设置为终止的信号 过程。