home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9273 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.4 KB  |  62 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!caen!hellgate.utah.edu!peruvian.utah.edu!rfrazier
  3. From: rfrazier%peruvian.utah.edu@cs.utah.edu (Robert Frazier)
  4. Subject: Pipe question
  5. Date: 22 Jul 92 00:46:51 MDT
  6. Message-ID: <1992Jul22.004651.21741@hellgate.utah.edu>
  7. Organization: University of Utah CS Dept
  8. Distribution: USA
  9. Lines: 51
  10.  
  11.  
  12.     I am trying to set up a circular pipe with telnet.  I want to 
  13. be able to read telnets stdout and write telnets stdin.  Here is what
  14. I have so far.  But it doesn't read anything.  I have used pipes like
  15. this with other applications, and they seemed to work.
  16.  
  17. #include <stdio.h>
  18.  
  19. int main(argc, argv)
  20.      int argc;
  21.      char **argv;
  22. {
  23.   int pid;
  24.   int fd1[2],fd2[2];
  25.   char buff[1000];
  26.   
  27.   pipe(fd1);
  28.   pipe(fd2);
  29.   close(1);
  30.   dup(fd1[1]);
  31.   close(0);
  32.   dup(fd2[0]);
  33.  
  34.   pid=fork();
  35.   if(!pid) {                      /*These means we are the child process*/
  36.     
  37.     close(0);
  38.     dup(fd1[0]);
  39.     close(1);
  40.     dup(fd2[1]);
  41.     sleep(1);
  42.     fprintf(stderr,"launching telnet\n");
  43.     execlp("telnet","peruvian.utah.edu",NULL);
  44.     fprintf(stderr,"Could not run telnet\n");
  45.     exit(0);
  46.   }
  47.  
  48. /*this code is the parent process whos stdout will go to the stdin of telnet*/
  49.   sleep(20);
  50.   fprintf(stderr,"about to read\n");
  51.   for(;;) {
  52.     read(0,buff,1);
  53.     fprintf(stderr,"%c",buff[0]);
  54.   }
  55. }
  56.  
  57.  
  58.     Any help is greatly appreciated
  59.  
  60.     Thanks,
  61.     R. Todd Frazier
  62.