Re: [GD-General] OT: Checking if any chars available on stdin under Windows
Brought to you by:
vexxed72
From: Mark W. <ma...@aw...> - 2004-04-23 15:15:59
|
Oops, meant to reply off list. And I also realised I didn't read the question properly. sorry! ----- Original Message ----- From: "Colin Fahey" <cp...@ea...> To: <gam...@li...> Sent: Friday, April 23, 2004 3:31 PM Subject: [GD-General] OT: Checking if any chars available on stdin under Windows > > 2004 April 22nd > Friday > > Off-Topic question here...but I just spent an hour doing Google > searching and reading other online documentation, and I'm not > finding any answers to the following: > > QUESTION: How can I check if stdin (standard input) has any > characters available for reading under WINDOWS (not Linux)? > > I thought (cin.rdbuf()->in_avail()) would be the cool hacked > solution -- but even after doing Sleep(1000), cin.sync_with_stdio(), > and wackier and wackier things to try to make "cin" up-to-date, > so to speak, the expression above ALWAYS yields zero, whether or > not there are characters available on the input stream. > (Compiled using Visual C++ 6.0 under Windows 2000) > > If I have a command line like the following: > > testapp > > then the following code blocks indefinitely: > > int c = cin.peek(); > > but if the command line is as follows: > > more textfile.txt | testapp > > then the application does not block. But in both > cases (cin.rdbuf()->in_avail()) is zero. > > How can "testapp" in the two command line examples > above DETECT which scenario (piped input or not) is > involved? That, I guess, is my real goal. I want to > know if the command line lacks the piping from > another app, since this means I shouldn't wait > forever for stdin data. > > I'd be willing to use a Win32 function to solve this > problem, but if it is really tricky, like creating a > thread, or something nutty, then it's probably not > worth it. Bleah, under Linux one can actually use > fnctl() to change stdin to non-blocking mode (but, > I assume, still buffered), which makes this problem > go away -- but no fnctl() under Windows. > > Anyhow, probably avoiding piping data through stdin > is the REAL solution to all of this mess, but that > decision is not mine to make. > > --- Colin > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek > For a limited time only, get FREE Ground shipping on all orders of $35 > or more. Hurry up and shop folks, this offer expires April 30th! > http://www.thinkgeek.com/freeshipping/?cpg=12297 > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > |