How do you tell if stdin/stdout is a terminal?

GALLOWAY gg10 at prism.gatech.EDU
Sun Aug 5 07:46:00 AEST 1990


I have seen programs which pipe binary data back and forth.  These programs
are usually "filters" for image data, etc.  Some are smart enough not to try
and read stdin, or write to stdout if the user has not added the proper 
redirections.  This can be quite useful if this binary data might be 
interpreted as terminal setup commands.

So, how do they do it on a generic unix box?

If I have a program named "foo" which can accept standard input if no file
name exists on the command line, and the user just types "foo", I want to
display usage.  If they type "foo < file" or "bar | foo" then I want to process
stdin.  Novice users see to be incredibly confused by typing "foo" and just
having it hang waiting for them to type in a binary image file, etc.

It would also be nice, if the output of "foo" was no ASCII to display a message
like "foo: output must not be terminal".  Again, so the novice user doesn't 
get blown away be several screenfulls of garbarge.  It seems most people like
to figure out how an unknown program works by just typing its name and waiting
for the old familar "usage: foo [ options ] arguments" line to pop up.

Thanks in advance,
Greg Galloway
gg10 at prism.gatech.edu



More information about the Comp.lang.c mailing list