about summary refs log tree commit diff
path: root/manual/examples/popen.c
diff options
context:
space:
mode:
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 0000000000..16ae32fa16
--- /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*/