in reply to Using Perl to launch another Perl script and generate error log if it fails

Something like this should do it. This assumes that your perl scripts return 0 on success anything else for failure
# untested @perlscripts = qw[1.pl 2.pl 3.pl]; foreach my $perlscript (@perlscripts) { system($perlscript); if($? == -1) { warn "Couldn't start $perlscript: $!"; } elsif($? != 0) { warn "Perl script $perlscript exited with: ". $? >> 8 } }
replace the warns with any error handling youd want to do.
Update: at the head of the file add
open(<FH>, ">logfile.txt") || die "Doh: $!";
and replace the warn's with
print FH "warning message";

Replies are listed 'Best First'.
Re: Re: Using Perl to launch another Perl script and generate error log if it fails
by Tomw72us (Initiate) on Mar 26, 2004 at 00:21 UTC
    If I wanted to replace the warn functions with a function that would write the same output to an error log, what would that look like? Thanks.

      If you aren't using your STDERR for anything else, just redirect it to the file and the warnings will show up there. You can do that in your shell script with foo.pl 2>> errlog.txt, or in Perl with:

      open STDERR, ">errlog.txt" or die "Whoa! I can't even log my errors: $!";

      Otherwise, you'll want the __WARN__ pseudo-signal:

      open ERRLOG, ">errlog.txt" or die; $SIG{__WARN__} = sub { my ($msg) = @_; $msg ||= q{Warning: something's wrong}; # Add the file and line number to $msg here # using the return values from caller(). print ERRLOG, $msg; };
      See also warn and caller in perlfunc and %SIG in perlvar.

      -- 
      LP^>