Note that there are some explanatory texts on larger screens.

plurals
  1. POLogging from output in Perl
    text
    copied!<p>I have a program that is supposed to run a set of other programs and collect their output for logging purposes. Everything is working fine as long as there is output to standard out.</p> <p>That leads me to my two problems:</p> <ol> <li><p>How can I capture both <code>STDIN</code> and <code>STDERR</code> of another program in one file?</p></li> <li><p>If there is no output at all (or output to <code>STDERR</code> only) the program will get stuck on the line:</p> <pre><code>while (&lt;$input&gt;) </code></pre></li> </ol> <p>How can I make the program wait for possible output from another program of indeterminate run time, and still continue if there is no output by the time the program finishes execution.</p> <p>Here is that section of the code</p> <pre><code>my $pid = open (my $input, '-|', "$prog $args") or push @errors, "A failute has occurred in $prog $args"; if(not @errors){ while (&lt;$input&gt;){ #POSSIBLE LOCATION FOR HANG UP IF NO PRINTING IS DONE if($input =~ /^END\n$/){ last; } print $fh $_; } } else{ print $fh "An error has occurred with executing \"$prog $args\""; } </code></pre> <p>note: <code>$fh</code> is my file handler used to write to my log file, and <code>@errors</code> is used for internally reporting errors in my program.</p> <p>EDIT: One problem I experienced with trying the <a href="http://p3rl.org/Proc%3a%3aReliable" rel="nofollow">Proc::Reliable</a> route is that it seems to have after effects on <code>STDOUT</code> and <code>STDERR</code>, and I would need to fix those after each call to run. This leads to another problem in my code. I am running in parallel and any change to <code>STDOUT</code> and <code>STDERR</code> effect all of the threads <em>(using Windows at least)</em>.</p> <p><a href="http://p3rl.org/IO%3a%3aCaptureOutput" rel="nofollow">IO::CaptureOutput</a> has the same issue for me, but it tries to correct the <code>STDOUT</code> and <code>STDERR</code> jumbling internally and causes the following error to occur:</p> <pre class="lang-none prettyprint-override"><code>Couldn't remove temp file 'C:\Users\SBLAKE~1\AppData\Local\Temp\m8E3pUGfOS' - Permission denied at C:/Perl/site/lib/IO/CaptureOutput.pm line 82 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload