免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4450 | 回复: 4
打印 上一主题 下一主题

shell脚本如何接收c函数的返回值 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-19 13:51 |只看该作者 |倒序浏览
file a.c

#include <stdio.h>

int main()
{
    int i;
    for(i=0; i<10; i++)
    {
        printf("%d\n",i);
    }

    return 15;
}

gcc -o a a.c

如何在shell脚本中接收a的返回值呢

论坛徽章:
0
2 [报告]
发表于 2010-01-19 13:55 |只看该作者
You can get the retrun value by using $? after you execute the 'a' program

论坛徽章:
0
3 [报告]
发表于 2010-01-19 14:09 |只看该作者
原帖由 nhw_cs 于 2010-1-19 13:55 发表
You can get the retrun value by using $? after you execute the 'a' program


before I asked the question, I have tried the method you mentioned, it have  no use.

论坛徽章:
0
4 [报告]
发表于 2010-01-19 14:17 |只看该作者
-bash-3.00$ cat a.c
#include <stdio.h>

int main()
{
    int i;
    for(i=0; i<10; i++)
    {
        printf("%d\n",i);
    }

    return 15;
}
-bash-3.00$ gcc -o a a.c
-bash-3.00$ ./a
0
1
2
3
4
5
6
7
8
9
-bash-3.00$ echo $?
15

论坛徽章:
0
5 [报告]
发表于 2010-01-19 14:23 |只看该作者

回复 #4 nhw_cs 的帖子

Thanks for your reply, I have test the program on a backup machine, it works!

there must be something wrong with my host. it feedbacks me a '0' value after I executed command "./a"
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP