Redirection question

D'Arcy J.M. Cain darcy at druid.uucp
Thu Nov 15 02:02:28 AEST 1990


In article <14447 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>What you really want to determine is whether or not input is coming
>from an interactive device.  This is in general impossible to
>ascertain.  The usual UNIX kludge is to invoke isatty(fileno(stdin));
>I don't know whether or not MS/DOS has something equivalent.  Anyway,
>it is not a reliable test, since just because something is coming via
>a terminal port does not necessarily mean that there is a human typing
>the input.  You should probably use a command option to determine how
>prompting should be done, if at all.  (One approach is to not prompt
>initially, but support an input command that enables/disables
>prompting; the UNIX System V "ed" uses this method.)

How about this for a kludge?  Have an input routine that takes a prompt
and a buffer argument and checks to see if there are characters waiting.
If not then issue the prompt.  as long as there are characters then you
just read.  If there is a human waiting for a prompt then you issue one.
If necessary you can add timing stuff so that slow terminals with stuff
in the pipe don't trigger the prompt.  Maybe I'll write this and post it
if I get a little time.

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   I support gun control.
West Hill, Ontario, Canada         |   Let's start with the government!
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list