Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uflorida!stat!sun13!prism!gg10 From: gg10@prism.gatech.EDU (GALLOWAY) Newsgroups: comp.lang.c Subject: How do you tell if stdin/stdout is a terminal? Keywords: stdin/stdout, unix, C, redirected I/O Message-ID: <12210@hydra.gatech.EDU> Date: 4 Aug 90 21:46:00 GMT Organization: Georgia Institute of Technology Lines: 23 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@prism.gatech.edu