Input from another tty

Leslie Mikesell les at chinet.chi.il.us
Tue Jan 29 07:21:44 AEST 1991


In article <NZVFw1w163w at bluemoon.uucp> dddean at 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 at chinet.chi.il.us



More information about the Comp.unix.programmer mailing list