home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!caen!hellgate.utah.edu!peruvian.utah.edu!rfrazier
- From: rfrazier%peruvian.utah.edu@cs.utah.edu (Robert Frazier)
- Subject: Pipe question
- Date: 22 Jul 92 00:46:51 MDT
- Message-ID: <1992Jul22.004651.21741@hellgate.utah.edu>
- Organization: University of Utah CS Dept
- Distribution: USA
- Lines: 51
-
-
- I am trying to set up a circular pipe with telnet. I want to
- be able to read telnets stdout and write telnets stdin. Here is what
- I have so far. But it doesn't read anything. I have used pipes like
- this with other applications, and they seemed to work.
-
- #include <stdio.h>
-
- int main(argc, argv)
- int argc;
- char **argv;
- {
- int pid;
- int fd1[2],fd2[2];
- char buff[1000];
-
- pipe(fd1);
- pipe(fd2);
- close(1);
- dup(fd1[1]);
- close(0);
- dup(fd2[0]);
-
- pid=fork();
- if(!pid) { /*These means we are the child process*/
-
- close(0);
- dup(fd1[0]);
- close(1);
- dup(fd2[1]);
- sleep(1);
- fprintf(stderr,"launching telnet\n");
- execlp("telnet","peruvian.utah.edu",NULL);
- fprintf(stderr,"Could not run telnet\n");
- exit(0);
- }
-
- /*this code is the parent process whos stdout will go to the stdin of telnet*/
- sleep(20);
- fprintf(stderr,"about to read\n");
- for(;;) {
- read(0,buff,1);
- fprintf(stderr,"%c",buff[0]);
- }
- }
-
-
- Any help is greatly appreciated
-
- Thanks,
- R. Todd Frazier
-