#include <stdio.h>
#include <string.h>
char *get_output_line(char *);
int main(int argc, char *argv[]) {
char res[256];
char *res_ptr = NULL;
res_ptr=get_output_line("ls -l");
if(res_ptr != NULL) {
strncpy(res,res_ptr,(size_t)256);
printf("Ls res: %s\n",res);
} else {
printf("Could not get result\n");
}
res_ptr=get_output_line("uname");
if(res_ptr != NULL) {
strncpy(res,res_ptr,(size_t)256);
printf("uname res: %s\n",res);
} else {
printf("Could not get result\n");
}
res_ptr=get_output_line("uptime");
if(res_ptr != NULL) {
strncpy(res,res_ptr,(size_t)256);
printf("uptime res: %s\n",res);
} else {
printf("Could not get result\n");
}
return 0;
}
char *get_output_line(char *command) {
FILE *my_file = NULL;
char result[256];
if(command == NULL) return NULL;
if(strlen(command) <= 0) return NULL;
my_file = popen(command,"r");
if(my_file == NULL) return NULL;
fgets(result,(size_t)256,my_file);
return result;
}