系统的返回值 [英] Return value of system

查看:96
本文介绍了系统的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

为了测试系统的返回值,我编写了2个程序,这些程序在下面显示了




计划1:


#include< stdio.h>

#include< stdlib.h>


int main(void)

{

int ret;


ret = system(&.; ./ TEST");

printf("返回值=%d \ n",ret);


返回ret;

}


计划2:


int main()

{

返回50;

}


program2的可执行文件名是TEST。我认为Program1

中的系统将返回program2将返回的任何内容,但它没有。什么

究竟系统会返回?如果我想获得program2的确切

返回值,该怎么办?


谢谢

解决方案

2006年1月17日21:03:59 -0800, va ****** @ rediffmail.com 写在

comp.lang.c:

大家好,
为了测试系统的返回值,我编写了2个程序,如下所示。

程序1:

#include< ; stdio.h>
#include< stdlib.h>

int main(无效)
{
int ret;

ret = system(&.; ./ TEST");
printf(" Return value =%d \ n" ret);

return ret;
}

程序2:

int main()
{
返回50;
}

可执行文件名program2是TEST。我认为Program1
中的系统将返回program2将返回的任何内容,但它没有。究竟系统将返回什么?如果我想获得program2的确切返回值,该怎么办?

谢谢



难道你的编译器没有提供文档,在线帮助或男人

页面吗?


你试过输入


" system()"功能


进入谷歌?


system()函数几乎完全是实现定义的。他们传递给它的

字符串,它们的意思,它们的解释方式,以及结果发生的结果都是实现定义的。


有一个例外,那就是。如果使用空指针

作为参数调用system(),则返回值会告诉您是否有可用的

命令shell。如果system(NULL)返回0,则表示没有可以使用的

命令shell。如果system(NULL)返回一个非零的
值,则有一个命令shell。


除此之外,由于它是完全实现定义的,你需要

查阅实施文档(编译器),
需要
来记录你打电话时会返回的内容。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


< blockquote>有什么办法吗?从程序2返回值并在程序1中打印






更改line:

printf(" Return value =%d \ n",ret); => printf(返回值=

%d \ n,ret%255);


Hi all,
To test the return value of system I wrote 2 programs which are shown
below.

Program 1:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int ret;

ret = system("./TEST");
printf("Return value = %d\n",ret);

return ret;
}

Program 2:

int main()
{
return 50;
}

The executable name of program2 is TEST. I thought system in Program1
will return whatever program2 will return, but It didn''t. What
exactly system will return?What should I do if I want to get the exact
return value of program2?

Thanks

解决方案

On 17 Jan 2006 21:03:59 -0800, va******@rediffmail.com wrote in
comp.lang.c:

Hi all,
To test the return value of system I wrote 2 programs which are shown
below.

Program 1:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int ret;

ret = system("./TEST");
printf("Return value = %d\n",ret);

return ret;
}

Program 2:

int main()
{
return 50;
}

The executable name of program2 is TEST. I thought system in Program1
will return whatever program2 will return, but It didn''t. What
exactly system will return?What should I do if I want to get the exact
return value of program2?

Thanks



Doesn''t your compiler provide documentation, online help, or man
pages?

Did you try typing

"system()" function

into Google?

The system() function is almost completely implementation-defined. The
strings they pass to it, what they mean, how they are interpreted, and
what happens as a result, are all implementation-defined.

With one exception, that is. If you call system() with a null pointer
as an argument, the return value tells you whether or not there is a
command shell available. If system(NULL) returns 0, there is no
command shell that you can use. If system(NULL) returns a non-zero
value, there is a command shell.

Beyond that, since it is completely implementation-defined, you need
to consult the documentation for your implementation (compiler), which
is required to document what it will return when you call it.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


Is there any way to get the value returned from Program2 and print it
in program1?



change the line:
printf("Return value = %d\n",ret); => printf("Return value =
%d\n",ret%255);


这篇关于系统的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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