Re: OT: Checking if any chars available on stdin under Windows

[email protected] (Mark Webster)
Newsgroups gmane.games.devel.general
Message-ID <20040424021232.GA8215@netbox>
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
> [email protected] - [email protected]
> YahooID: tweety_04_01
> 
> 
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Mark
> Webster
> Sent: April 23, 2004 11:26 AM
> To: [email protected]
> 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" <[email protected]>
> > To: <[email protected]>
> > 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
> > > [email protected]
> > > 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
> [email protected]
> 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
> [email protected]
> 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-general
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=557
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.