Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool2.mu.edu!samsung!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!gargoyle!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.programmer Subject: Re: Input from another tty Message-ID: <1991Jan28.202144.10099@chinet.chi.il.us> Date: 28 Jan 91 20:21:44 GMT References: Organization: Chinet - Chicago Public Access UNIX Lines: 40 In article dddean@bluemoon.uucp (David D. Dean) writes: > I was wondering if there was a special command that I had to use >to have a program of mine - when I run it - accept input from another >terminal? I have tried many times with different forms of: > read ANW < /dev/dk??? > > while (true) do > cat (filename) > done& > (then have the other terminal write to (filename) > > >I think that what I'll have to do, is to setup a sub-routine to always >check a set file for new input and then grep the info in that file. As with most programming problems there are many solutions and the most appropriate one depends on what you are trying to do. The most likely problems with trying to directly read from another terminal are: A) You don't have read permission on the device. (Solution: chmod appropriatly). B) Another program (i.e. the user's shell) is reading at the same time. (Solution: prevent that program from reading for the duration of the access - for example, tell the shell to sleep awhile). C) If no other program is using the device, the stty modes need to be set appropriately for the terminal. (Solution: use stty redirected to the other device within a loop that prevents the devices from being closed until you are done with it.) One quick and easy solution is to use a FIFO to pass the information. (If your system supports FIFOs). Just "/etc/mknod FIFO p". Then you can write to it from one program and read from another with it acting pretty much like a pipe. Then you would run a program at the other terminal that interacts with the user and writes to the FIFO. Les Mikesell les@chinet.chi.il.us