【发布时间】:2014-09-08 18:12:22
【问题描述】:
我想使用system() 执行一个main() 返回2 的可执行文件。
这就是我所做的
#include <stdio.h>
#include <string.h>
int main(int argc, char *agrv[])
{
char command[7];
strcpy(command, "./test1");
printf("The return value: %d\n", system(command));
return 0;
}
而test1 是
#include <stdio.h>
int main(void)
{
printf("test1 has been executed and its return value is 2\n");
return 2;
}
这就是我得到的
test1 has been executed and its return value is 2
The return value: 512
我的问题是为什么我会收到512。
【问题讨论】:
-
@AntonH OP 并不打算打印字符串。
-
@AntonH 不,你错了
-
@DrewMcGowen 你说得对,我读得太快了。
-
command太小。这是未定义的行为。 -
Here 是用户获得 512 的链接。在这种情况下,它与 SQL 调用结合使用。