Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to determine the source of stdin

2 views
Skip to first unread message

Isaac Chen

unread,
Mar 1, 2000, 3:00:00 AM3/1/00
to
Hi,

How does one know if the stdin is from the console, a pipe,
or redirected from other file? Is there a standard way to get
that information, or it's different for each platform? If so,
what are the ways for DOS, UNIX, Win32 console mode?

Thanks.

Isaac Chen


ke...@hplb.hpl.hp.com

unread,
Mar 1, 2000, 3:00:00 AM3/1/00
to
In article <89ihvo$1...@news.dns.microsoft.com>,

"Isaac Chen" <ycc...@vlsi.ee.hwh.edu.tw> writes:
> Hi,
>
> How does one know if the stdin is from the console, a pipe,
> or redirected from other file?

One doesn't.

> Is there a standard way to get
> that information, or it's different for each platform?

No.

> If so,
> what are the ways for DOS, UNIX, Win32 console mode?

I *strongly* suggest not knowing.

First, your code will need to be compiled under different conditions
on each platform. This is not good. And you'll have to maintain
the different versions as new platforms emerge. (Consider that your
list leaves out the Macs and RISC OS, for example.)

Second, *why* do you need to know? The usual reason is so that
your code can prompt (or not). I've deal with this by having a
command-line argument; eg the default can be "no prompt" and
specifying `-prompt="spoo- "` encourages you with spoo (it's
quite fresh, ambassador).

--
Chris "or use -noprompt" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html

0 new messages