home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <fcntl.h>
- #include <fpipe.h>
- #include <signal.h>
-
- #define READ_END 0
- #define WRITE_END 1
- extern int fpipe();
- extern char *fgets();
-
- char buf[BUFSIZ];
-
- main()
- {
- FILE *args[2];
- enum {first, next} time = first;
- int pid;
-
- /* if( (pid = fpipe(STD_ERR_SCR, args, "./tst",0)) == -1 ) */
-
- if( (pid = fpipe(STD_ERR_NUL, args, "/usr/bin/mailx", "-u", "gb", "-f","$HOME/mbox",0)) == -1 )
-
- {
- puts("AARRRRRGGGG!!!!");
- exit(-1);
- }
-
- for(;;)
- {
- fcopy(args[READ_END], "/dev/tty", NO_BLOCK);
- printf("enter command\n");
- gets(buf);
- if( *buf == 27 )
- break;
- fprintf(args[WRITE_END], "%s\n", buf);
- fflush(args[WRITE_END]);
- }
- /*
- * closing the file pointers also sends 'CTRL-D' (EOF) to the child
- * process. In the case of 'mailx' this will kill it.
- */
- fcopy(args[READ_END], "/dev/tty", NO_BLOCK);
- fclose(args[READ_END]);
- fclose(args[WRITE_END]);
- return 0;
- }
-