Another approach is to use a pipe, if you have those functions available to you (they're non-standard). Be careful with this method though, sometimes the pipe will get stuck if things don't go right. Use with caution!
Code:
/* This was written under Borland 5.5 */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buf[BUFSIZ];
FILE *fp;
if ((fp = _popen("ping 127.0.0.1", "r")) == NULL)
{
perror("pipe failure");
return (EXIT_FAILURE);
}
while (fgets(buf, sizeof(buf), fp))
printf ("OUTPUT: %s\n", buf);
_pclose(fp);
return (EXIT_SUCCESS);
}