我有 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 错误处理程序中,以便捕获返回错误代码并将其传递给回调函数?
最佳答案
I need the exit status of the binary so i can return it back to user defined callback in the first snippet.
根据the docs ,您不需要监听 exit
事件来执行此操作:
The callback gets the arguments
(error, stdout, stderr)
. On success,error
will benull
. On error,error
will be an instance ofError
anderror.code
will be the exit code of the child process, anderror.signal
will be set to the signal that terminated the process.
关于javascript - 在 exec 的函数回调中使用 on.exit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24513529/