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

  1. Newsgroups: comp.unix.programmer
  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:50:31 MDT
  6. Message-ID: <1992Jul22.005031.21998@hellgate.utah.edu>
  7. Organization: University of Utah CS Dept
  8. Distribution: USA
  9. Lines: 74
  10.  
  11. Newsgroups: comp.unix.bsd
  12. Subject: Pipe question
  13. Summary: 
  14. Expires: 
  15. Sender: 
  16. Followup-To: 
  17. Distribution: USA
  18. Organization: University of Utah CS Dept
  19. Keywords: 
  20.  
  21. Newsgroups: comp.unix.questions
  22. Subject: Pipe question
  23. Summary: 
  24. Expires: 
  25. Sender: 
  26. Followup-To: 
  27. Distribution: USA
  28. Organization: University of Utah CS Dept
  29. Keywords: 
  30.  
  31.  
  32.     I am trying to set up a circular pipe with telnet.  I want to 
  33. be able to read telnets stdout and write telnets stdin.  Here is what
  34. I have so far.  But it doesn't read anything.  I have used pipes like
  35. this with other applications, and they seemed to work.
  36.  
  37. #include <stdio.h>
  38.  
  39. int main(argc, argv)
  40.      int argc;
  41.      char **argv;
  42. {
  43.   int pid;
  44.   int fd1[2],fd2[2];
  45.   char buff[1000];
  46.   
  47.   pipe(fd1);
  48.   pipe(fd2);
  49.   close(1);
  50.   dup(fd1[1]);
  51.   close(0);
  52.   dup(fd2[0]);
  53.  
  54.   pid=fork();
  55.   if(!pid) {                      /*These means we are the child process*/
  56.     
  57.     close(0);
  58.     dup(fd1[0]);
  59.     close(1);
  60.     dup(fd2[1]);
  61.     sleep(1);
  62.     fprintf(stderr,"launching telnet\n");
  63.     execlp("telnet","peruvian.utah.edu",NULL);
  64.     fprintf(stderr,"Could not run telnet\n");
  65.     exit(0);
  66.   }
  67.  
  68. /*this code is the parent process whos stdout will go to the stdin of telnet*/
  69.   sleep(20);
  70.   fprintf(stderr,"about to read\n");
  71.   for(;;) {
  72.     read(0,buff,1);
  73.     fprintf(stderr,"%c",buff[0]);
  74.   }
  75. }
  76.  
  77.  
  78.     Any help is greatly appreciated
  79.  
  80.     Thanks,
  81.     R. Todd Frazier
  82.     rfrazier@peruvian.utah.edu
  83.  
  84.     
  85.