Sorry to post this again, but is seems that once the thread is a day or two old, no one looks at it and I still don't have an answer... I am submitting multiple commands in parallel using Run_parallel using a Tk GUI. The commands that I am running can take up to 5 minutes to complete (or time out). I am submitting these in the background on a UNIX system (&). With the current subroutine, If the commands are submitted one at a time, STDERR comes back fine. However, if I submit several at once, I only get STDERR back for the LAST command to complete. How can I get STDERR back for ALL commands? I cannot use any CPAN modules.
sub run_parallel { my $job_count = shift; unless (0 < $job_count) { confess("run_parallel called without a positive parallel job count +!"); } my @to_start = @_; my %running; my %errors; my $is_running = 0; while (@to_start or %running) { if (@to_start and ($is_running < $job_count)) { # Launch a job my $job = shift @to_start; unless (ref($job)) { $job = [$job]; } open (NULL, $null_file) or confess("Cannot read from $null_file: +$!"); my $proc_id = open3("<&NULL", \*CMD_OUT, \*CMD_ERR, @$job); $running{$proc_id} = $job; ++$is_running; } else { # collect a job my $proc_id = wait(); if (! exists $running{$proc_id}) { confess("Reaped unknown process $proc_id!"); } elsif ($?) { # Oops my $job = $running{$proc_id}; my ($cmd, @args) = @$job; my $err = "Running '$cmd' gave return code '$?'"; if (@args) { $err .= join "\n\t", "\nAdditional args:", @args; } $errors{$proc_id} = $err; } delete $running{$proc_id}; --$is_running; } } return %errors; $mw_status_window->fileevent(\*CMD_OUT, 'readable', \&read_out); $mw_status_window->fileevent(\*CMD_ERR, 'readable', \&read_err); } sub read_out { my $line = <CMD_OUT>; unless ($line) { close(CMD_OUT); } else { print "green", "$line\n"; } } sub read_err { my $line = <CMD_ERR>; unless ($line) { close(CMD_ERR); } else { print "red", "$line\n"; } }

In reply to Gathering STDERR from multiple commands.... by Capt_Howdey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.