randy@umn-cs.cs.umn.edu (Randy Orrison) (04/14/88)
System: Silicon Graphics running SGI Unix 3.5 (?) Silicon Graphics running ATT System V Release 3.2 I'm working on a project where we want to have a program talking to another machine. I'd like to be able to have the program open up a couple pipes and the fork off telnet to do the talking, but simple experiments with telnet are proving to be dismal failures. I've tried the following approaches: cat - | telnet cat -u - | telnet telnet < /dev/tty The first two result in telnet accepting the "open" command and connecting, but then ignoring the rest of my input, until I hit the intr key when telnet acts as if it were processing my past input at the telnet> prompt. E.g.: % cat - | telnet telnet> open george ...connected... Silicon Graphics (george) (nothing.... i type: open george) (nothing.... i hit DEL) telnet> already connected to george telnet> connection closed % (rough paraphrase). The last one (telnet < /dev/tty) hangs up the console and requires a reboot. On the vax running 4.3 here, the first two do about the same things, but the last works just fine. I suspect that telnet is doing some ioctls that screw up pipes. Does anyone have any ideas what I can do? Note that I need the solution for System V so i don't have ptys available (always did like BSD better...). Thanks for all you help! -randy -- Randy Orrison, Control Data, Arden Hills, MN randy@ux.acss.umn.edu (Anyone got a Unix I can borrow?) {ihnp4, seismo!rutgers, sun}!umn-cs!randy What is a magician but a practising theorist? -- Obi-Wan Kenobi
randy@ncifcrf.gov (The Computer Grue) (04/17/88)
I'm pretty sure that the problem here is that when telnet does the open it puts the terminal into raw mode and simply transfers characters to the remote system. This means that you need to send <CR> to end lines instead of <LF>, which is the normal unix end of line character. This explains everything you described except the console hanging on the tty indirect, but then I always knew SGI had flaky OS software! I had this same problem attempting to get telnet working on input from a regular disk file. Try translating <LF> to <CR> on the cat (does tr buffer? If so, you'll have to write a C program to do it); that should fix your problem. Hope this helps . . . -- Randy -- Randy Smith @ NCI Supercomputer Facility c/o PRI, Inc. Phone: (301) 698-5660 PO Box B, Bldng. 430 Uucp: ...!uunet!ncifcrf.gov!randy Frederick, MD 21701 Arpa: randy@ncifcrf.gov
barnett@vdsvax.steinmetz.ge.com (Bruce G. Barnett) (04/18/88)
In article <443@ncifcrf.ncifcrf.gov> randy@ncifcrf.gov (The Computer Grue) writes: [ telnet with a script] |This means that you need to send |<CR> to end lines instead of <LF>, which is the normal unix end of |line character. Don't forget the Login: and Password: lines. These are not terminated by <CR> or <LF>. I hacked together a simple program for a remote telnet script. (Our Internet gateway doesn't do IP forwarding and isn't BSD based.) I am not satified I did it the most efficient way. I forked a telnet process and connected to it using pipes. I then used fcntl to add the FNDELAY flag. I experimented with different values to distinguish from a timeout and a line without a <cr><lf>. I wrote my own buffering scheme. Anyhow, the program works - more-or-less, but I can't help wondering is there is a better way. Anyone have any suggestions? I plan to study the sources of telnet and rlogin - for inspiration. Sigh ... it is amazing how a simple 2-hour hack grows in size to fill all available time. -- Bruce G. Barnett <barnett@ge-crd.ARPA> <barnett@steinmetz.UUCP> uunet!steinmetz!barnett