#include <stdio.h>
int main(void)
{
FILE *file = popen("date", "r");
if (file == NULL) {
perror("popen");
return 1;
}
char buffer[256] = { 0 };
while (fgets(buffer, 255, file) != NULL) {
printf("example->%s", buffer);
}
pclose(file);
return 0;
}
$ gcc a.c && ./a.out
example->Tue May 29 16:26:46 CST 2018