Signal Handling/Term::ReadLine problem in Perl

From: John C. Worsley (lx_at_openvein.com)
Date: 01/21/04

  • Next message: Daniel Heneghan, GT Solutions: "Save your job, deport H1 B's now"
    Date: 20 Jan 2004 17:51:00 -0800
    
    

    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/
    

  • Next message: Daniel Heneghan, GT Solutions: "Save your job, deport H1 B's now"

    Relevant Pages

    • Error checking on File I/O
      ... a readline means EOF _or_ error. ... Assuming I haven't missed something, if there are any Perl historians, ... language lawyers or source code gurus out there, I'd like to know why it's ...
      (comp.lang.perl.misc)
    • Re: Reproducible sig 11 with bash2
      ... >3) Hit the arrow up key, ... is a mismatch between the version of readline in bash2, ... version which is in the base system. ... once I'm sure they will generate the correct set of commands). ...
      (freebsd-current)
    • Trouble with readline in cpan, perl debug on Mac OS X
      ... I have reinstalled cpan, and the readline libraries, but even though ... Could it be that the Perl that is ...
      (comp.lang.perl.modules)
    • Re: term::readline, need to change default prompt char props
      ... characteristics of the string I ask the "readline" method to use as a ... For me, a single arrow suffices to switch, but it takes two ... affect history items added before the input loop is begun. ... Stonehenge Perl Training ...
      (perl.beginners)
    • Re: Cant find syntax error
      ... and it put me in an endless loop:). ... The (readline) operator is required to read a line from the filehandle $fh ... use Perl; ...
      (comp.lang.perl.misc)