View Single Post
  #8 (permalink)  
Old April 19th, 2005, 10:08 AM
ciderpunx ciderpunx is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey Merediths,

Yah, but popen isn't part of ANSI C, and shafiq (I'm guessing) is on a windoze system. I'm not sure if windows supports popen(), as you're essentially opening a UNIX pipe. Anyhow, here's a bit of demo code. Works on Linux, YMMV.

/*
 * Purpose: Program to demonstrate the popen function.
 *
 * to do: Check that the 'popen' was successfull.
 *
 * Author: M J Leslie.
 * Date: 08-Jan-94
*/

#include <stdio.h>

main()
{
  FILE *fp;
  char line[130]; /* line of data from unix command*/

  fp = popen("ls -l", "r"); /* Issue the command. */

                    /* Read a line */
  while ( fgets( line, sizeof line, fp))
  {
    printf("%s", line);
  }
  pclose(fp);
}

HTH

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
Reply With Quote