Back to index

glibc  2.9
popen.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 void
00005 write_data (FILE * stream)
00006 {
00007   int i;
00008   for (i = 0; i < 100; i++)
00009     fprintf (stream, "%d\n", i);
00010   if (ferror (stream))
00011     {
00012       fprintf (stderr, "Output to stream failed.\n");
00013       exit (EXIT_FAILURE);
00014     }
00015 }
00016 
00017 /*@group*/
00018 int
00019 main (void)
00020 {
00021   FILE *output;
00022 
00023   output = popen ("more", "w");
00024   if (!output)
00025     {
00026       fprintf (stderr,
00027               "incorrect parameters or too many files.\n");
00028       return EXIT_FAILURE;
00029     }
00030   write_data (output);
00031   if (pclose (output) != 0)
00032     {
00033       fprintf (stderr,
00034               "Could not run more or other error.\n");
00035     }
00036   return EXIT_SUCCESS;
00037 }
00038 /*@end group*/