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

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