Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^5: $SIG{ALRM} and windows vista?

by BrowserUk (Pope)
on Jan 04, 2010 at 07:18 UTC ( #815533=note: print w/ replies, xml ) Need Help??


in reply to Re^4: $SIG{ALRM} and windows vista?
in thread $SIG{ALRM} and windows vista?

Windows doesn't have signals

No, but it simulates some of them:

use strict; use warnings; use 5.010; print 'Enter your password: '; my $password = eval { local $SIG{ALRM} = sub {die "timeout\n"}; alarm 5; # return <STDIN>; sleep 10; }; alarm 0; if ($@ =~ /timeout/) { print "You timed out.\n"; } __END__ [ 7:18:01.22] C:\test>alarmit.pl Enter your password: You timed out.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^5: $SIG{ALRM} and windows vista?
Download Code
Re^6: $SIG{ALRM} and windows vista?
by ikegami (Pope) on Jan 04, 2010 at 07:20 UTC
Re^6: $SIG{ALRM} and windows vista?
by afoken (Parson) on Jan 04, 2010 at 08:29 UTC

    A little bit of bean counting:

    Windows has no signals, and it does not emulate them. It's perl that implements an incomplete emulation of Unix signals, without support from Windows.

    From perlport:

    Don't count on signals or %SIG for anything.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      It's perl that implements an incomplete emulation of Unix signals

      If we're being pedantic, it is Perl on Windows that does the emulation.

      Which is of course what I meant, though I agree, not exactly what I said.

Re^6: $SIG{ALRM} and windows vista?
by 7stud (Deacon) on Jan 04, 2010 at 19:46 UTC

    On Windows Vista, your code doesn't do anything useful. Specifically, your code fails to display the message "Enter your password:" and then wait for the user to enter their password. Instead, your code does nothing, then prints out "Enter your password: you timed out."

    In an effort to get "Enter your password: " to display immediately, I tried setting the output buffer to flush output immediately by setting $| = 1, but that didn't change the result.

      On Windows Vista, your code doesn't do anything useful.

      It does! It demonstrates that alarm works, when the operation, (sleep in this case), doesn't involve IO. Ie. The sleep 10; was interupted by the alarm 5. And that was the only reason I posted it.

      For a solution to your problem that works, see Term::ReadKey


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      Instead, your code does nothing, then prints out "Enter your password: you timed out."

      As it should. His code demonstrates that alarm will interrupt sleep on Windows.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-11-27 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (180 votes), past polls