<?xml version="1.0" encoding="windows-1252"?>
<node id="1003497" title="Perl Term::ReadLine::Gnu Signal Handling Difficulties" created="2012-11-12 15:00:26" updated="2012-11-12 15:00:26">
<type id="115">
perlquestion</type>
<author id="1003492">
sgt_b2002</author>
<data>
<field name="doctext">
&lt;p&gt;Hi everyone,&lt;/p&gt;

&lt;p&gt;I'm using Term::ReadLine::Gnu and have run into a problem with signal handling. Given the script below and a TERM signal sent to the script, the handler for the TERM signal is not triggered until after the enter key is pressed. Using Term::ReadLine:Perl this does not occur.&lt;/p&gt;

&lt;p&gt;I've read that Term::ReadLine::Gnu has its own internal signal handlers, but frankly I'm at a loss as to how to work with them.&lt;/p&gt;

&lt;p&gt;I've reviewed the &lt;a href="http://search.cpan.org/~hayashi/Term-ReadLine-Gnu-1.20/Gnu.pm#Term::ReadLine::Gnu_Variables"&gt;Gnu_Variables&lt;/a&gt; and tried setting the rl_catch_signals variable to 0, but that didn't help. Ideally, I'd like to work with the Gnu signal handlers, but I'll settle for disabling them too.&lt;/p&gt;

&lt;p&gt;To be absolutely specific, I need the TERM handler to trigger after the signal is received instead of waiting for the enter key to be pressed.&lt;/p&gt;

&lt;p&gt;Any help or advice is very much appreciated!&lt;/p&gt;

&lt;code&gt;
#!/usr/bin/perl

use strict;
use warnings;
use Term::ReadLine;

$SIG{TERM} = sub { print "I got a TERM\n"; exit; };

my $term = Term::ReadLine-&gt;new('Term1');
$term-&gt;ornaments(0);
my $prompt = 'cmd&gt; ';
while ( defined (my $cmd = $term-&gt;readline($prompt)) ) {
    chomp($cmd);
    if ($cmd =~ /^help$/) {
        print "Help Menu\n";
    }
    else {
        print "Nothing\n";
    }
}
&lt;/code&gt;</field>
</data>
</node>
