我应该怎么做才能通过命令行C程序的整个返回值? [英] What should I do to get the whole return value of c-program from command line?
问题描述
我有一个简单的C程序./ my_program
I have a simple C-program "./my_program"
#include <stdio.h>
int main (int argc , char **argv) {
unsigned int return_result = 0x474;
printf("return_result = %d = 0x%x \n",return_result,return_result);
return return_result;
}
其结果是,该程序打印:
As a result, this program prints:
return_result = 1140 = 0x474
我想获得C程序的bash脚本中的返回值。
根据这个链接
<一href=\"http://stackoverflow.com/questions/8230265/anyway-to-get-return-value-of-c-program-from-command-line\">Anyway从命令行得到C程序的返回值?
我应该从$得到这个变量?
I want to get a return value of c-program within bash script. According to this link Anyway to get return value of c program from command line? I should get this variable from $?
但是,当我推出这样的命令造成的:
But when I launch such commands consequence:
./my_program
echo $?
我得到
116
这是显而易见的,即116 = 0x74(最低字节)。
但是,我想对整个事件无符号整型值。
哪里不对?我应该怎么做才能通过命令行C程序的整个返回值?这是不是只是无符号整型类型。我应该在的情况下做,如果我创造了一些复杂的类型,例如, - 结构
It is obviously, that 116 = 0x74 (the lowest byte). But I'd like to get the whole unsigned int value. What is wrong? What should I do to get the whole return value of c-program from command line? This is not about only "unsigned int" type. What should I do in case if I created some complicated type, for example, - structure.
我试过这样:
return ((unsigned int) return_result_section_size);
这是行不通的。
推荐答案
退出codeS在Unix上被限制在单字节。如果你想输出更多,你可以把它写到标准输出或不是文件。
Exit codes on Unix are restricted to a single byte. If you want to output more, you could write it to stdout or to a file instead.
那么为什么C标准法令,主
收益 INT
,而不是字符
?我不知道...
Then why does the C standard decree that main
returns int
and not char
? I have no idea...
这篇关于我应该怎么做才能通过命令行C程序的整个返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!