|
我想通过管道传递gcc编译代码后输出的信,可是老是失败
把printf("%s\n",str);去掉,还是会输出信息,怎么才能让
gcc的输出传到str中呀?
代码如下:
#include <stdio.h>
int main()
{
FILE* fd;
char str[80];
printf("Now this process will call popen system call\n");
if((fd = popen("gcc -o test test.c","r")) == NULL)
{
printf("Call popen failed\n");
return 1;
}
else
{
while(fgets(str,80,fd) != NULL)
{
printf("%s\n",str);
}
}
pclose(fd);
return 0;
} |
|