It’s funny, I didn’t realize (or had forgotten) how easy it is to execute a command and grab its output.
#include
main()
{
FILE *fpipe;
char *command="ls -l";
char line[256];
if ( !(fpipe = (FILE*)popen(command,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
while ( fgets( line, sizeof line, fpipe))
{
printf("%s", line);
}
pclose(fpipe);
}
from http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html