aboutsummaryrefslogtreecommitdiff
path: root/manual/examples/popen.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
committerRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
commit28f540f45bbacd939bfd07f213bcad2bf730b1bf (patch)
tree15f07c4c43d635959c6afee96bde71fb1b3614ee /manual/examples/popen.c
downloadglibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.zip
glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.gz
glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.bz2
initial import
Diffstat (limited to 'manual/examples/popen.c')
-rw-r--r--manual/examples/popen.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/manual/examples/popen.c b/manual/examples/popen.c
new file mode 100644
index 0000000..16ae32f
--- /dev/null
+++ b/manual/examples/popen.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+write_data (FILE * stream)
+{
+ int i;
+ for (i = 0; i < 100; i++)
+ fprintf (stream, "%d\n", i);
+ if (ferror (stream))
+ {
+ fprintf (stderr, "Output to stream failed.\n");
+ exit (EXIT_FAILURE);
+ }
+}
+
+/*@group*/
+int
+main (void)
+{
+ FILE *output;
+
+ output = popen ("more", "w");
+ if (!output)
+ {
+ fprintf (stderr, "Could not run more.\n");
+ return EXIT_FAILURE;
+ }
+ write_data (output);
+ pclose (output);
+ return EXIT_SUCCESS;
+}
+/*@end group*/