[comp.unix.wizards] Reading raw input from /dev/tty using shell

barnett@crdgw1.crd.ge.com (Bruce Barnett) (03/17/89)

Does anyone know a clever method of reading raw data from /dev/tty
using a shell script and standard Unix tools?

I have a C program, but was wondering if there is some way I could
accomplish this using a Vanilla SunOS 4.0 system.

The data is variable length, 6 to 8 characters, and always ends with
a known character (ascii 't'). In fact, the data should be in the input
queue before the program is started, and is a terminal's response
to an escape sequence.

Perhaps using stty to set eol to 't', or sending a signal?

Call me a purist, but I was wondering if I could replace a 10 line C program
with a 5 line shell script? :-)

--
Bruce G. Barnett	<barnett@crdgw1.ge.com>  a.k.a. <barnett@[192.35.44.4]>
			uunet!steinmetz!barnett, <barnett@steinmetz.ge.com>

jimmy@pyrps5 (Jimmy Aitken) (03/30/89)

In article <52@crdgw1.crd.ge.com> barnett@crdgw1.crd.ge.com (Bruce Barnett) writes:
>Does anyone know a clever method of reading raw data from /dev/tty
>using a shell script and standard Unix tools?
This is the method that I shell script that I use to chnage attributes
of a sun window. The main program has lots of options and needs to
know the current position of the window read via escape sequences.
Note that you musn't type anything whilst it's trying to read the
input as it would get messed up with the stuff that the sun window is
"typing". This runs fine under sunOS 3.5
The code fragment goes something like:
stty raw > /dev/tty
echo -n "escape sequencs that causes the string to be returned" > /dev/tty
ch=`dd </dev/tty count=1 2>/dev/null`
stty cooked > /dev/tty

This can be used e.g:
echo -n "${esc}[18t"
to get the size of the window
>Call me a purist, but I was wondering if I could replace a 10 line C program
>with a 5 line shell script? :-)

Or even 4 line...