i've got this long-standing problem i'm trying to solve:
how can a C or C++ application know if cin has data without blocking? i
understand that there is no 100% portable way to do this, but i don't need
portable (i need Linux ;). i've googled all over for this and haven't found
a single relevant example.
i've looked at other programs, like gzip, to see how they do it, but they
typically simply assume input-from-stdin if no other command-line arguments
are given. My app, on the other hand, should start in interactive mode if
cin is not waiting to give us something, otherwise it should process cin
$> myapp < foo
should read in foo and skip interactive mode
(To be clear, the only part i'm hung up on is the checking of stdin. i
currently work around this with a --stin flag, which tells the app to read
stdin and then exit.)
Is this a pipe dream?
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.