Signal Handling/Term::ReadLine problem in Perl

Discussion in 'Perl' started by John C. Worsley, Jan 21, 2004.

  1. 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 -
    http://www.openvein.com/
     
    John C. Worsley, Jan 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yves Dorfsman

    no cleanup on TERM signal

    Yves Dorfsman, May 2, 2008, in forum: Python
    Replies:
    4
    Views:
    333
    Laszlo Nagy
    May 2, 2008
  2. gavino
    Replies:
    4
    Views:
    541
    gavino
    Sep 20, 2010
  3. Jean-Michel
    Replies:
    0
    Views:
    362
    Jean-Michel
    Dec 22, 2007
  4. Art Werschulz

    Term::ReadLine::GNU problem

    Art Werschulz, Jan 1, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    195
    Art Werschulz
    Jan 1, 2006
  5. Andrew DeFaria
    Replies:
    1
    Views:
    212
    Ben Morrow
    Jan 30, 2008
Loading...

Share This Page