popen() will let you execute a command and capture the output via a redirected pipe.
Code:
FILE *fd;
char cmdoutput[496]={'\0'};
fd=popen("ps -ef", "r");
while(1){
if(fgets(cmdoutput,4095,fd)!=NULL){
/* cmdoutput has a line of output */
} else{
if(feof(fd)) break;
perror("Pipe processing error");
exit(EXIT_FAILURE);
}
}
pclose(fd);