Article View: comp.unix.programmer
Article #77Pipe question
From: Robert Frazier
Date: Wed, 22 Jul 1992 06:50
Date: Wed, 22 Jul 1992 06:50
74 lines
1846 bytes
1846 bytes
Newsgroups: comp.unix.bsd
Subject: Pipe question
Summary:
Expires:
Sender:
Followup-To:
Distribution: USA
Organization: University of Utah CS Dept
Keywords:
Newsgroups: comp.unix.questions
Subject: Pipe question
Summary:
Expires:
Sender:
Followup-To:
Distribution: USA
Organization: University of Utah CS Dept
Keywords:
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
rfrazier@peruvian.utah.edu
Technical Details
Message-ID:
<1992Jul22.005031.21998@hellgate.utah.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!caen!hellgate.utah.edu!peruvian.utah.edu!rfrazierShow Full Headers
Complete Article Headers
Newsgroups: comp.unix.programmer Path: arc1-ca.pugleaf.net!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:50:31 MDT Message-ID: <1992Jul22.005031.21998@hellgate.utah.edu> Organization: University of Utah CS Dept Distribution: USA Lines: 74