<font face="courier new,monospace">My next test after moving from using backticks to run_cmd()<br>for executing and capturing external data has uncovered<br>another side effect that I don't know how to get around.<br><br>

"Perl END blocks are not run if run_cmd(stuff) is executing."<br><br>In the following code, I try to capture CTL C to perform<br>some clean-up, and I also want my module's END block to<br>get executed.  Now that I've moved to using run_cmd(),<br>

it seems that while run_cmd() is executing... if I<br>(for example) send it a INT signal, the INT signal is<br>caught, but the END block doesn't get executed.  If I<br>wait for the run_cmd() to finish and then press CTL C,<br>

the END block _is_ executed.<br><br>Comments or suggestions are welcome.<br><br>TIA<br>Fulko<br><br>------------- code example </font><font face="courier new,monospace">starts -------------<br><br></font><font face="courier new,monospace">#!/usr/bin/perl<br>

<br>use strict;<br>use warnings;<br>use Coro;<br>use AnyEvent;<br>use AnyEvent::Util;<br><br>END { print "INSIDE END BLOCK\n"; }<br><br>sub make_catcher {<br>    my $s = shift;<br>    return sub { signal_catcher($s); };<br>

}<br><br>sub signal_catcher {<br>    my ($name) = @_;<br><br>    print "\ncatcher called with '$name'\n";<br>    exit if $name eq 'INT';<br>}<br><br>sub get_cmd_data {<br>    my ($cmd) = @_;<br>
<br>
    my $buffer = '';<br>    my $ps_cv = run_cmd $cmd, ">" => sub {$buffer .= $_[0] if (scalar @_);};<br>    $ps_cv->recv;<br>    return \$buffer;<br>}<br><br>sub obtainer {</font><br><br><font face="courier new,monospace">    print "END not accessible during run_cmd()... wait 5 seconds till its done\n";<br>

    my $bufRef = get_cmd_data("sleep 5");<br>    print "run_cmd() done, END is now reachable on CTL C\n";<br>}<br><br>my $mysig =  AnyEvent->signal (signal => 'INT', cb => make_catcher('INT') );<br>

my $obtainer = AnyEvent->timer(after => 1, interval => 15, cb => \&obtainer);<br>AnyEvent->condvar->wait;<br><br></font><font face="courier new,monospace">------------- code example </font><font face="courier new,monospace">ends -------------</font><br>