Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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
[marioroy]: We made it all the way to the end. The expience was magical. I not good at sports. Someone or thing was there.
erix considers extracting a catalog ...
[karlgoethebier]: marioroy: Racket ball is considered harmful, like Squash
[marioroy]: Wait till folks see what MCE::Hobo can do in the upcoming release. Multiple instances, nested spawning, 3 levels, doesn't matter. it works on Windiows too.
[Lady_Aleena]: I hate sites that tell me to turn ad-blocker off. They should know better.
[marioroy]: s/Windiows/ Windows/
[Discipulus]: marioroy can you expand that Niagara's fall history?
erix only sees fallen angels
erix if it weren't for bad luck, I'd have no luck at all
Discipulus Windiows the OS of native americans..

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-05-29 08:46 GMT
Find Nodes?
    Voting Booth?