Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!usc!apple!olivea!tymix!cirrusl!sunstorm!dhesi From: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Newsgroups: comp.lang.c Subject: Re: Redirection question Message-ID: <2701@cirrusl.UUCP> Date: 15 Nov 90 19:13:45 GMT References: <31530029@hpcvia.CV.HP.COM> Sender: news@cirrusl.UUCP Organization: Cirrus Logic Inc. Lines: 22 >>Is there a _portable_ way to recognize whether input comes from >>stdin or from another stream ? Absolutely none! But isatty(fd) works reasonably well on many systems. Beware of just doing a single test, however (which you may have been thinking of doing after seeing some other postings). You might want to do it like this: if (isatty(fileno(stdin)) && isatty(fileno(stdout))) { ... interactive code ... } else { ... noninteractive code ... } This way you don't print a prompt to the output stream unless it's connected to a tty, and you don't print a prompt unless the input is coming from a tty. You can also explicitly open /dev/tty to print the prompt, but that's much less portable than isatty() alone. -- Rahul Dhesi UUCP: oliveb!cirrusl!dhesi