I found that the script given by @ijw (modified to be what it is below) does not work in Active State Perl version 5.10.1:
This is perl, v5.10.1 built for MSWin32-x86-multi-thread (with 2 registered patches, see perl -V for more detail)
My change below adds autoflush calls (otherwise sleep below will not display output of print output at all while sleeping):
#!/usr/bin/perl use IO; use strict; use warnings; # Set autoflushing on to stdout and stderr. Otherwise, system() call and stdout output does not show up in proper sequence, # especially on Windows: STDOUT->autoflush(1); STDERR->autoflush(1); $SIG{INT}=\&clean; sub clean { print "caught\n"; exit (0); } print "before sleep\n"; sleep 100; print "after sleep and then exiting\n"; exit (0);
When I commented on the following lines in the script above:
$SIG{INT}=\&clean; sub clean { print "caught\n"; exit (0); }
And then pressing CTRL-C during sleep, the script terminates and displays this message:
Terminating on signal SIGINT(2)
Therefore, it should still be true (well, for ActiveState Perl v5.10.1) that man perlwin32 indicates:
... most of the "signal ()" implementations on Win32 are badly crippled ....
For future reference:
source share