PracticeDev/study_clang/system_status/test_popen.c

23 lines
418 B
C

#include <stdlib.h>
#include <stdio.h>
#define BUF_SIZE 1024
char buf[BUF_SIZE];
int main(void)
{
FILE * p_file = NULL;
p_file = popen("cat /proc/version", "r");
if (!p_file) {
fprintf(stderr, "Erro to popen");
}
while (fgets(buf, BUF_SIZE, p_file) != NULL) {
fprintf(stdout, "%s", buf);
}
pclose(p_file);
return 0;
}