Non-blocking STDIN read? 
Author Message
 Non-blocking STDIN read?

I'm hacking together a PHP script which will run as a non-web CLI app.  It's
going to keep it's self busy in a loop, monitoring some things, but needs to
be controllable by the user while it's doing this.

The question is, is there a non-blocking way to see if a character is
waiting on STDIN?  That way I can call the function every so often from my
loop and see if the user wants something, and take an appropriate action
(like pop up a prompt where they can type in a command) but if they don't,
have it return immediately so I can go on about my looping business.

Unfortunately this needs to be done under Windows, if it matters.

I've tried stream_set_blocking( STDIN, FALSE ) and doing an fgetc( STDIN )
but that doesn't seem to work -- in fact fgetc() doesn't actually seem to
want to return until I hit return, blocking aside..

Hopefully this is at all possible, or I'll have to revert to an even
cheesier way of communicating with my already cheesy app.

--

|  Bob Maple  |  bobm_at_burner_dot_com  |  [http] burner.com
|
|  Thom Yorke: "Here's to getting hitched, Space Ghost."
|  "Yeah..  Lets drink until our hearts stop."



Tue, 21 Jun 2005 13:52:16 GMT  
 Non-blocking STDIN read?
ncurses http://www.php.net/manual/en/ref.ncurses.php

/usr/bin/joe


Quote:
> I'm hacking together a PHP script which will run as a non-web CLI app.
It's
> going to keep it's self busy in a loop, monitoring some things, but needs
to
> be controllable by the user while it's doing this.

> The question is, is there a non-blocking way to see if a character is
> waiting on STDIN?  That way I can call the function every so often from my
> loop and see if the user wants something, and take an appropriate action
> (like pop up a prompt where they can type in a command) but if they don't,
> have it return immediately so I can go on about my looping business.

> Unfortunately this needs to be done under Windows, if it matters.

> I've tried stream_set_blocking( STDIN, FALSE ) and doing an fgetc( STDIN )
> but that doesn't seem to work -- in fact fgetc() doesn't actually seem to
> want to return until I hit return, blocking aside..

> Hopefully this is at all possible, or I'll have to revert to an even
> cheesier way of communicating with my already cheesy app.

> --

> |  Bob Maple  |  bobm_at_burner_dot_com  |  [http] burner.com
> |
> |  Thom Yorke: "Here's to getting hitched, Space Ghost."
> |  "Yeah..  Lets drink until our hearts stop."



Tue, 21 Jun 2005 14:03:43 GMT  
 Non-blocking STDIN read?

Quote:
> ncurses http://www.php.net/manual/en/ref.ncurses.php

Not in Windoze.

--

|  Bob Maple  |  bobm_at_burner_dot_com  |  [http] burner.com
|
|  Thom Yorke: "Here's to getting hitched, Space Ghost."
|  "Yeah..  Lets drink until our hearts stop."



Tue, 21 Jun 2005 14:10:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. non-blocking sys.stdin.read() on win32?

2. read stdin NON-BLOCKING

3. non-blocking reading from stdin?

4. stdin non blocking and fileevent

5. How do I get a non-blocking stdin?

6. non-blocking gets to stdin / SIGIO

7. non-blocking reads losing data

8. Unable to do non-blocking read on socket

9. non-blocking-read function

10. Need to do a non-blocking read with Verdix (Sun) Ada

11. Non-blocking pipe read under Windows NT

12. How do I do a non-blocking read() ?

 

 
Powered by phpBB® Forum Software