我有两个程序,用 C 编写的程序“a”和用 NodeJS 编写的程序“b”。我从程序“a”执行程序“b”,如下所示:
int retVal = system("node /path/to/progB.js");
printf("%d",retVal);
我的程序“b”看起来像这样:
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
if (body === 'something') {
process.exitCode = 0;
} else if (body === 'something else') {
process.exitCode = 1;
} else {
process.exitCode = 2;
}
} else {
console.log("ERR" + body + response);
process.exitCode = 3;
}
});
返回程序“a”,返回值为 0
、256
、512
或 768
。二进制为:0000 0000 0000
、0001 0000 0000
、0010 0000 0000
、0011 0000 0000
。通过检查这些数字,我可以清楚地看到我的返回值是第 8 位和第 9 位,因此我的返回值向左移动了 8 位。但为什么呢?
系统是带有 Raspbian 的 Raspberry Pi,编译器是 gcc 版本 6.3.0
最佳答案
您必须使用宏WIFEXITED
、WEXITSTATUS
等来解释system
的结果。有关宏的更多详细信息,请参阅 wait(2) 的手册页。
关于c - NodeJS 退出代码左移 8 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54998270/