If it's from a file, I want to fputs()
the text. But if it's from the keyboard,
I won't (don't want it typed, then
fputs()'d.
SRB
srb...@sbcglobal.net wrote:
> Can a program detect if it's stdin is
> coming from keyboard input vs. being
> redirected from a file?
Not in standard C, it can't.
But, with a platform-specific extension, it often can.
> If it's from a file, I want to fputs()
> the text. But if it's from the keyboard,
> I won't (don't want it typed, then
> fputs()'d.
You'll either have to resort to some sort of signal data (like a command
argument), or use a platform-specific extension to determine whether stdin
comes from a file or an interactive device.
- --
Lew Pitcher
Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)
iD8DBQFDD7VAagVFX4UWr64RAi2yAJ9M7NGcb3z4zRVIkuJ8Eg7WKaQdFQCfYBie
Wl2MOzXg/kxLYBvIVGwErRw=
=Fiqc
-----END PGP SIGNATURE-----
However, on most unixlike systems there are methods available,
which are OT here. The OP can examine one such in my id2id-20,
which is available at:
<http://cbfalconer.home.att.net/download/id2id-20.zip>
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
I found the most straightforward tactic in a similar situation
(whether to issue a prompt or not, for an interactive interpreter)
to be a command-line flag. The program no longer needs to be able
to answer the question.
--
Chris "electric hedgehog" Dollin
Almost all predictions about life in 2015 are wrong in some fundamental
respect.