Thread: 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:26:27
|
Ok, the solution appears to be to check _eof(0); - If it returns -1, there's nothing on stdin. I *think* that's the answer you're looking for. Mark Webster > ----- 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 > > > > > |
From: tweety <mi...@sy...> - 2004-04-23 20:33:43
|
Just a shot in the dark here, but on windows wouldn't eof return true only then it encounters ^Z? ---------------------------------- Peace and love, Tweety mi...@sy... - twe...@us... YahooID: tweety_04_01 -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Mark Webster Sent: April 23, 2004 11:26 AM To: gam...@li... Subject: Re: [GD-General] OT: Checking if any chars available on stdin under Windows Ok, the solution appears to be to check _eof(0); - If it returns -1, there's nothing on stdin. I *think* that's the answer you're looking for. Mark Webster > ----- 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 > > > > > ------------------------------------------------------- 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 |
From: <ma...@aw...> - 2004-04-24 02:07:52
|
Well, if eof(0) returns -1, it means there was an error with file descriptor 0 (stdin) indicating that the stdin is not open. This tells us whether the program is being piped to or not. This is a simple non-blocking way to determine if the program can read from stdin or not. You can verify this in MSVC help :) Mark Webster On Fri, Apr 23, 2004 at 04:33:38PM -0400, tweety wrote: > Just a shot in the dark here, but on windows wouldn't eof return true only > then it encounters ^Z? > > ---------------------------------- > Peace and love, > Tweety > mi...@sy... - twe...@us... > YahooID: tweety_04_01 > > > > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On Behalf Of Mark > Webster > Sent: April 23, 2004 11:26 AM > To: gam...@li... > Subject: Re: [GD-General] OT: Checking if any chars available on stdin under > Windows > > Ok, the solution appears to be to check _eof(0); - If it returns -1, there's > nothing on stdin. > > I *think* that's the answer you're looking for. > > Mark Webster > > > ----- 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 > > > > > > > > > > > > ------------------------------------------------------- > 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 > > > > > ------------------------------------------------------- > 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 > |