首页 > 解决方案 > 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 位。但为什么?5127680000 0000 00000001 0000 00000010 0000 00000011 0000 0000

系统是带有 Raspbian 的 Raspberry Pi,编译器是 gcc 版本 6.3.0

标签: cnode.jsreturn-value

解决方案


你必须使用宏WIFEXITEDWEXITSTATUS和朋友来解释结果system。有关宏的更多详细信息,请参见 wait(2) 的手册页。


推荐阅读