you can use popen following way:
Code:
#include <stdio.h>
int main()
{
#define BUFSIZE 1024
char buf[1024];
FILE *fp = NULL;
char *cmd = "ls -al /home/";
int nbytes = 0;
int fbytes = BUFSIZE;
int ch =0;
fp = popen(cmd, "r");
if (fp == NULL) {
printf("unable to open %s", cmd);
exit(0);
}
while (nbytes < fbytes && (ch = fgetc(fp)) != EOF)
buf[nbytes++] = ch;
buf[nbytes] = 0;
pclose(fp);
printf("output for %s %d:\n %s", cmd , nbytes, buf);
return 0;
}