Wed Jul 14 21:15:20 2010: Request 59322 was acted upon. Transaction: Correspondence added by CHM Queue: Win32-Console Subject: SetConsoleCtrlHandler function not supported Broken in: 0.09 Severity: Important Owner: Nobody Requestors: c...@cpan.org Status: open Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=59322 >
On Wed Jul 14 20:00:48 2010, dbec...@roadrunner.com wrote: > 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. I think it has something to do with the Term::ReadLine stuff. If I run the perldl shell, end then type Ctrl-C followed by <Enter> I get the following: perldl> # Typed Ctrl-C perldl> # Typed <Enter> perldl> # Typed Ctrl-C perldl> # Typed <Enter> perldl> # Typed Ctrl-C perldl> # Typed <Enter> (Although sometimes extra newline for some reason) perldl> # Typed Ctrl-C and then again without <Enter> perldl> Ctrl-C detected END failed--call queue aborted at C:\chm\strawberry\perl\bin/perldl line 550. Terminate batch job (Y/N)? n C:\chm\strawberry> So the problem appears that the 1st Ctrl-C is caught but something in the readline part prevents reloading of the signal handler so an immediate Ctrl-C will send another "SIGINT" which will not be caught and then the console control handler will be called which offers to exit the CMD console. (Presumably, the default handler was also called from the 2nd Ctrl-C in perl which is why that application exited.... I think I've convinced myself it is tied in with the Term::ReadLine::Perl stuff but don't know how it could be fixed. If that is the case, having the missing SetConsoleCtrlHandler() routine might not help either. --Chris