Hey dude(s)

Also in the meantime, I have tried

#!/opt/local/bin/perl -w use IPC::Run qw( run new_chunker input_avail ); use File::Basename; #need two arguments: script to run and mailing list (comma-separated m +1 ids) $#ARGV == 1 || die "Error: Need exactly two arguments!\n"; ($base, $dir, $ext)=fileparse($ARGV[0],'\..*'); #Do some machinations to create a unique overall log file @now=localtime; #month returned by localtime() are zero-indexed. #got to pad the zeroes for the time/date elements $mo=sprintf("%02d",$now[4]+1); $d=sprintf("%02d",$now[3]); $y=$now[5]+1900; $h=sprintf("%02d",$now[2]); $mi=sprintf("%02d",$now[1]); $workdir="/fma/prod1/isa/logs"; $logfile="$workdir/$base-$y$mo$d.$h$mi.m1jwc03.log"; open(LOG,">$logfile") || die "Error: Could not open $logfile: $!\n"; my $oldfh=select(LOG) || die "Error: Could not select LOG: $!\n"; print "*-*-begin_run-*-*\n"; ($distlist = $ARGV[1]) =~ s/,/ /g; print "*-*-on_error $distlist-*-*\n"; chdir("$dir"); @cmd=$ARGV[0]; $SIG{CHLD} = sub { print "NOTE: in sig{CHLD}\n"; # if (waitpid($pid, 0) > 0){sleep(1);}; }; sub new_prefixer { my ($prefix) = @_; return sub { my ($in_ref, $out_ref) = @_; return input_avail && do { $$out_ref = join('', $$out_ref, $prefix, $$in_ref); $$in_ref = ''; 1 }; } } sub new_printer { if (defined ($_[0])){ return sub { print ($_[0]); } }else{ return sub { print '$_[0] undefined in new_printer',"\n"; } } } { my $printer = new_printer(); run (\@cmd, '>', \*LOG, '2>', new_chunker(), new_prefixer('STDERR: +'), $printer) or die("Error executing child. Child returned $&\n"); } print "*-*-end_run-*-*\n"; close(LOG);
Which doesn't give me any nasty output in the shell, but the log only gets STDOUT and after the STDOUT there are a series of lines that look like this:
$_[0] undefined in new_printer
$_[0] undefined in new_printer
$_[0] undefined in new_printer
.....
$_[0] undefined in new_printer
$_[0] undefined in new_printer
NOTE:  in sig{CHLD}
$_[0] undefined in new_printer
$_[0] undefined in new_printer
*-*-end_run-*-*
so for some reason new_printer() is not getting the right data?

Any and all comments appreciated, and I hope you don't mind that I am taking liberties with your code (to simplify and adapt to my needs).

Thanks again.

_________________________________________________________________________________
Without me, it's just aweso


In reply to Re^4: Prepending a string to STDERR output, and logging STDOUT & STDERR synchronously to a file by OfficeLinebacker
in thread Prepending a string to STDERR output, and logging STDOUT & STDERR synchronously to a file by Anonymous Monk

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.