Programming and posix - April 2002

April 3, 2002
Solution Symposium
Page 51
hp e3000
programming
and posix
pipes the easy popen() way
#include <stdio.h>
int main() {
FILE *mypipe; char buf[256];
mypipe = popen("callci showtime", "r"); /* readable pipe */
while (fgets(buf, sizeof(buf), mypipe) != NULL)
printf("pipe read = %s\n",buf); /* read until EOF */
pclose(mypipe);
mypipe = popen("/bin/sed -e 's/^/pipe write = /'", "w");
fputs("testing\n",mypipe); fputs("123\n",mypipe); /* write 2 lines */
pclose(mypipe);
}