#include <stdlib.h>
system("clear");
#include <stdio.h>
int main (){
char c[100];
FILE *fp;
fp=popen("curl cooolr.cn","r");
fgets(c, sizeof(c), fp);
printf("%s",c);
pclose(fp);
return(0);
}
示例
#include <stdio.h>
#include <string.h>
char * system(char *command) {
char buffer[1024];
static char output[65535];
memset(output, 0, sizeof(output));
FILE *fp = popen(command, "r");
while (fgets(buffer, sizeof(buffer), fp)) {
strcat(output,buffer);
}
fclose(fp);
return output;
}
int main() {
char *output = system("curl http://baidu.com");
printf("%s",output);
return 1;
}