summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/popen.c
blob: 4df7a5cb638e514feee18444dc0278747338aee9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * 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);
}