glibc/manual/examples/popen.c

39 lines
647 B
C
Raw Normal View History

1995-02-18 02:27:10 +01:00
#include <stdio.h>
#include <stdlib.h>
void
1995-02-18 02:27:10 +01:00
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,
"incorrect parameters or too many files.\n");
1995-02-18 02:27:10 +01:00
return EXIT_FAILURE;
}
write_data (output);
if (pclose (output) != 0)
{
fprintf (stderr,
"Could not run more or other error.\n");
}
1995-02-18 02:27:10 +01:00
return EXIT_SUCCESS;
}
/*@end group*/