Xref: utzoo comp.lang.c:30837 comp.unix.questions:24385 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!ficc!peter From: peter@ficc.ferranti.com (Peter da Silva) Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: How do you tell if stdin/stdout is a terminal? Keywords: stdin/stdout, unix, C, redirected I/O Message-ID: Date: 6 Aug 90 20:08:44 GMT References: <12210@hydra.gatech.EDU> Reply-To: peter@ficc.ferranti.com (Peter da Silva) Followup-To: comp.unix.questions Organization: Xenix Support, FICC Lines: 22 This is touched on in the latest FAQ for comp.unix.questions, under "how do I tell if my program is running in the background". It is not a C problem, but a UNIX problem. However, here are the answers. In article <12210@hydra.gatech.EDU> gg10@prism.gatech.EDU (GALLOWAY) writes: > 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(isatty(fileno(stdin))) { usage(); exit(0); } > It would also be nice, if the output of "foo" was no ASCII to display a > message like "foo: output must not be terminal". if(isatty(fileno(stdout))) { user_error(); usage(); exit(2); } -- Peter da Silva. `-_-' +1 713 274 5180. 'U`