irick@ecn.purdue.edu (GarBear Irick) (10/16/90)
The following program is SUPPOSED to allow me to affect the stdin of another terminal whose /dev/ttyXX is owned by me also, but it loses. It works if I take out the code to try and open another device driver and simply put chars into my OWN stdin, but I can't get it to close its own control terminal, open a new one, and put chars into stdin. Any clues? Thanks to all the C gurus out there who reply by E-mail... #include <sys/ioctl.h> #include <stdio.h> /* Program should take 1st argument as terminal device driver (/dev/ttyXX), and echo all remaining args onto the std_IN_ of the terminal... */ main(argc,argv) int argc; char *argv[]; { int j; char *s; if (ioctl(3,TIOCGPGRP,(char *) &j) == -1) (void) dup2(0,3); /* THIS CODE LOSES */ ioctl(0,TIOCNOTTY,"/dev/tty"); close(0); fopen(0,argv[1]); /* BACK TO OK CODE */ for (j = 2;j < argc;j++) { for (s = argv[j];*s;s++) (void) ioctl(3,TIOCSTI,s); if (j < argc - 1) (void) ioctl(3,TIOCSTI," "); } } -- Gary A. Irick, Purdue University | "You can log out any time you like, INTERNET: irick@en.ecn.purdue.edu | But you can never leave!" UUCP: ...!pur-ee!irick | (apologies to The Eagles)