title: perl alarm with subprocess
body: <p>I have a perl script that runs a series of batch scripts for regression testing.  I want to implement a timeout on the batch scripts.  I currently have the following code.</p>
  
  <pre><code>    my $pid = open CMD, "$cmd 2&gt;&amp;1 |";
      eval {
                 # setup the alarm
                 local $SIG{ALRM} = sub { die "alarm\n" };
                 # alarm on the timeout
                 alarm $MAX_TIMEOUT;
                 log_output("setting alarm to $MAX_TIMEOUT\n");
  
                 # run our exe
                 while( &lt;CMD&gt; ) {
                         $$out_ref .= $_;
                 }
                 $timeRemaining = alarm 0;
              };
              if ($@) {
                      #catch the alarm, kill the executable
              }
  </code></pre>
  
  <p>The problem is that no matter what I set the max timeout to, the alarm is never tripped.  I've tried using Perl::Unsafe::Signals but that did not help.</p>
  
  <p>Is this the best way to execute the batch scripts if I want to be able to capture their output? Is there another way that would do the same thing that would allow me to use alarms, or is there another method besides alarms to timeout the program?</p>
  
  <p>I have built a test script to confirm that alarm works on with my perl and windows version, but it does not work when I run a command like this.</p>
  
  <p>I'm running this with activeperl 5.10.1 on windows 7 x64.</p>