我应该怎么做才能从命令行获取 c-program 的整个返回值? [英] What should I do to get the whole return value of c-program from command line?

查看:18
本文介绍了我应该怎么做才能从命令行获取 c-program 的整个返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 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 
",return_result,return_result);
   return return_result;

}

因此,该程序会打印:

return_result = 1140 = 0x474 

我想在 bash 脚本中获取 c-program 的返回值.根据这个链接无论如何从命令获取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(最低字节).但我想获得整个 unsigned int 值.怎么了?我应该怎么做才能从命令行获取 c-program 的整个返回值?这不仅仅是无符号整数"类型.如果我创建了一些复杂的类型,例如 - 结构,我该怎么办.

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);

它不起作用.

推荐答案

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 标准规定 main 返回 int 而不是 char?我不知道...

Then why does the C standard decree that main returns int and not char? I have no idea...

这篇关于我应该怎么做才能从命令行获取 c-program 的整个返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆