Chris Marshall via RT wrote:
Tue Jul 13 12:59:28 2010: Request 59322 was acted upon.
Transaction: Ticket created by CHM
       Queue: Win32-Console
     Subject: SetConsoleCtrlHandler function not supported
   Broken in: 0.09
    Severity: Important
       Owner: Nobody
  Requestors: c...@cpan.org
      Status: new
 Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=59322 >

A persistent and pernicious problem with using perl
from the win32 console is the fact that Ctrl-C can
not be caught.  This makes it very difficult to implement
cross-platform code that works on win32.

If SetConsoleCtrlHandler() were available to handle
these "signals" that would prevent Ctrl-C in a
Term::ReadLine::Perl session in a CMD shell window
from killing the perl instance and even the CMD
shell if the exit routine query is not answered
in the negative.

I notice that there is commented out code for just
this in the 0.09 version of Win32::Console.  Is
there a reason it was not enabled?  Even a limited
implementation that keeps perl and the CMD shell
from exiting would be a huge win.

Can't you already trap Ctrl-C in the script ?
What happens when you run this ? :

test.pl:

my $cnt = 0;
sub handler { print "Caught a SIG '$_[0]'\n"; exit if ++$cnt > 2; }
$SIG{INT}  = \&handler;
while (1) { Win32::Sleep(100); }
__END__

> perl test.pl
^C      (type Ctrl-C)
Caught a SIG 'INT'
^C
Caught a SIG 'INT'
^C
Caught a SIG 'INT'

Should catch Ctrl-C, print the message and exit after the 3rd time.
Not sure if changing the sleep to your readline call would alter the
result - try changing it.

Reply via email to