Chris Marshall via RT wrote:

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.

Looks like 1) you have to stop reading after you get an EOF
from readline; 2) readline seems to catch the first ^C and
quits working after that - then you can catch ^C OK; 3) you
can't create a new Readline obj after it fails.

New test case:

use strict;
use warnings;
use Term::ReadLine;

$| = 1;
my $cnt = 0;
sub handler {
        print "Caught a SIG '$_[0]' - continuing\n";
        die "Got three" if ++$cnt > 2;
}
$SIG{INT}  = \&handler;

my $term = new Term::ReadLine 'ProgramName';
while (1) {
        my $input = $term->readline('prompt> ');
        if (not defined $input) {
                print "EOF on input\n";
        } elsif ($input eq 'q') {
                print "quitting\n"; exit;
        } else {
                printf "Got: '%s'\n", $input;
        }
        Win32::Sleep(1000);     # stop runaway console
}

__END__

There's definitely some work that could be done in readline
to make this a little more friendly and some docs to go with.

Reply via email to