c - NodeJS 退出代码向左移动 8 位
问题描述
我有两个程序,用 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
或. 二进制是:, , , . 通过检查这些数字,我可以清楚地看到我的返回值是第 8 位和第 9 位,因此我的返回值向左移动了 8 位。但为什么?512
768
0000 0000 0000
0001 0000 0000
0010 0000 0000
0011 0000 0000
系统是带有 Raspbian 的 Raspberry Pi,编译器是 gcc 版本 6.3.0
解决方案
你必须使用宏WIFEXITED
,WEXITSTATUS
和朋友来解释结果system
。有关宏的更多详细信息,请参见 wait(2) 的手册页。
推荐阅读
- youtube-dl - 如何安装 youtube-dl ubuntu 18.04
- url - URL 编码 \x 个字符
- privacy - Facebook 应用隐私政策 URL - 如果我不是公司,我应该怎么做?而且我不使用来自用户 netiher 的任何数据?
- go - 如何同时获得 AffectedRows 和 Row?
- javascript - 如何确保 Magento 2 中的 RequireJS 在加载其他脚本之前加载 jQuery?我发现嵌套需要解决这个问题
- python - 为什么打印 itertools.takewhile() 返回的对象的内容会破坏以后使用它的代码?
- ms-access-2010 - 使用 Java 从 MS Access 向文件系统写入/读取 OLE 对象
- python - 如何在通过 selenium 自动化时使用 beautifulsoup 打印 href 属性?
- git - git diff 两个不同存储库的简单方法
- django - Ingress 和 Ingress 控制器如何将它们与 NodePort 服务一起使用?