1,system的用法:
#include<stdio.h>
int main()
{
system("ls -l");
return 0;
}
[tangtao@localhost test]$ ./a.out
总用量 24
-rw-r--r-- 1 tangtao wuhanrd 358 6月 22 08:34 1_test.c
-rw-r--r-- 1 tangtao wuhanrd 65 6月 22 10:59 2_test.c
-rwxr-xr-x 1 tangtao wuhanrd 8400 6月 22 11:01 a.out
-rwxrwxrwx 1 tangtao wuhanrd 9 6月 22 10:40 file
system 返回值说明:
-1:创建子进程失败
对于其它值,先用返回值除以256,商对应的含义如下:
0:命令运行成功
1:通用未知错误
2:误用shell命令
126:命令不可执行
127:没有找到命令
128:无效退出参数
130:命令通过Ctrl+C终止
255:退出状态码越界
2,poen的用法:
#include<stdio.h>
int main()
{
FILE* fp = NULL;
fp = popen("ls -l","r");
char aTest[1000];
int iRet = fread(aTest,1000,1,fp);
if(iRet < 0)
{
printf(