Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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.

Replies are listed 'Best First'.
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.

Re: STDIN and timeout or auto answer
by kyle (Abbot) on Feb 22, 2008 at 21:58 UTC
      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.)
      alarm doesn't work on Windows, at least not here. Neither does select with non-socket handles, so that's out too.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://669653]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2018-03-23 03:24 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (287 votes). Check out past polls.