home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1694 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  897 b   |  47 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <fpipe.h>
  4. #include <signal.h>
  5.  
  6. #define READ_END 0
  7. #define WRITE_END 1
  8. extern int fpipe();
  9. extern char *fgets();
  10.  
  11. char buf[BUFSIZ];
  12.  
  13. main()
  14. {
  15. FILE *args[2];
  16. enum {first, next} time = first;
  17. int pid;
  18.  
  19. /*    if( (pid = fpipe(STD_ERR_SCR, args, "./tst",0)) == -1 )  */
  20.  
  21.     if( (pid = fpipe(STD_ERR_NUL, args, "/usr/bin/mailx", "-u", "gb", "-f","$HOME/mbox",0)) == -1 ) 
  22.  
  23.     {
  24.         puts("AARRRRRGGGG!!!!");
  25.         exit(-1);
  26.     }
  27.  
  28.     for(;;)
  29.     {
  30.         fcopy(args[READ_END], "/dev/tty", NO_BLOCK);
  31.         printf("enter command\n");
  32.         gets(buf);
  33.         if( *buf == 27 )
  34.             break;
  35.         fprintf(args[WRITE_END], "%s\n", buf);
  36.         fflush(args[WRITE_END]);
  37.     }
  38. /*
  39.  * closing the file pointers also sends 'CTRL-D' (EOF) to the child
  40.  * process.   In the case of 'mailx' this will kill it.
  41.  */
  42.     fcopy(args[READ_END], "/dev/tty", NO_BLOCK);
  43.     fclose(args[READ_END]);
  44.     fclose(args[WRITE_END]);
  45.     return 0;
  46. }
  47.