Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Welcome to the Monastery
 
PerlMonks  

STDIN and timeout or auto answer

by kansaschuck (Sexton)
on Feb 22, 2008 at 21:41 UTC ( #669653=perlquestion: print w/ replies, xml ) Need Help??
kansaschuck has asked for the wisdom of the Perl Monks concerning the following question:

Let's say I have a program with STDIN. It pops up on the screen and says: " Keep running?" with logic behind the scene the take the input and does stuff. Now let's say someone is snoozing on the couch and the default is after 10 minutes is to yes, please keep running. Is there some time out? Can I, in my code, answer STDIN after 10 minutes and go on? thanks Windows XP ActiveState 5.10.

Comment on STDIN and timeout or auto answer
Re: STDIN and timeout or auto answer
by kyle (Abbot) on Feb 22, 2008 at 21:58 UTC
      alarm doesn't work on Windows, at least not here. Neither does select with non-socket handles, so that's out too.
      Does Term::ReadKey work on Active State Perl? I know it works under Cygwin perl. If alarm and select are out, the only solution might be Term::ReadKey and busy waiting (i.e. have a loop which constantly checks the time and Term::ReadKey.)
Re: STDIN and timeout or auto answer
by ikegami (Pope) on Feb 22, 2008 at 23:00 UTC
    One way would be to use native system calls.
    1. Win32API::File's GetOsFHandle to get the underlying OS handle.
    2. ReOpenFile the handle with FILE_FLAG_OVERLAPPED.
    3. CreateEvent to create the event on which to wait.
    4. ReadFile to start waiting for data.
    5. WaitForSingleObject with a timeout to wait for input.
    6. CloseHandle to release the event and the file handle.

    The system calls can be accessed via Win32::API and via other modules (such as Win32API::File and Win32::Event).

    Update: Oh oops, I had suggested CreateFile, but that isn't applicable. Replaced with ReOpenFile.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://669653]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-04-19 01:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (475 votes), past polls