一 点睛
system的原型如下, 其作用是运行以字符串参数的形式传递给它的命令并等待该命令的完成。其作用等价于在shell中执行命令sh -c string。
#include <stdlib.h>
int system(const char *string);
二 代码
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("running cat with system.\n");
system("cat system1.c");
printf("-----------\nDone.\n");
return 0;
}
三 编译运行
[root@localhost test]# g++ system1.c -o system1
[root@localhost test]# ./system1
running cat with system.
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("running cat with system.\n");
system("cat system1.c");
printf("-----------\nDone.\n");
return 0;
}
-----------
Done.
四 说明
其运行结果与sh -c "cat system1.c"类似。
[