Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Signal Handling/Term::ReadLine problem in Perl (http://www.velocityreviews.com/forums/t24765-signal-handling-term-readline-problem-in-perl.html)

John C. Worsley 01-21-2004 01:51 AM

Signal Handling/Term::ReadLine problem in Perl
 
I've got an extremely inscrutable problem here using Perl's
Term::ReadLine::Gnu module. I'm using Perl 5.8.0, readline 4.3 and
Term::ReadLine::Gnu 1.14.

The problem is specific to catching INT signals while in the
readline() function. In C, when I've set a SIGINT handler using
signal(), it is immediately called (even in readline()) when I hit
CTRL-C. Likewise in Perl, if I am reading in a while() loop from
STDIN, and I have set the $SIG{INT} handler, it is immediately called
on CTRL-C being struck.

However, the maddening thing here is that when calling readline() from
within Perl, when I hit CTRL-C, it doesn't call the signal handler
until AFTER I hit ENTER on the keyboard. I can even use
tab-completion, reverse-i-search and other readline features after I
have hit CTRL-C, but only after I hit enter, the CTRL-C is processed.

How on earth do I solve this? :) I've googled for over an hour trying
to find a solution and haven't come up with anything. I tried messing
around with some of the Term Attribs to make sure it wasn't using its
own signal handlers but never got different results. Simple script to
duplicate the problem follows.

------------------------------------------------------------------------------
#!/usr/bin/perl
use IO;
use Term::ReadLine;

STDOUT->autoflush();
$SIG{INT} = sub { die("CTRL-C"); };

$term = new Term::ReadLine 'ProgramName';
while (1) {
$input = $term->readline('prompt> ');
print "Got: $input\n";
}

------------------------------------------------------------------------------

Any help would be appreciated!

Best wishes,
John C. Worsley
--
John C. Worsley - Artist - lx@openvein.com
http://www.openvein.com/


All times are GMT. The time now is 07:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.