Perl Exit Recording

I have a program that should run a set of other programs and collect their results for logging. Everything works fine as long as the standard version is issued.

This leads me to two of my problems:

  • How can I capture both STDIN and STDERR another program in one file?

  • If there is no output (or output only to STDERR ), the program will get stuck in the line:

     while (<$input>) 

How can I make a program wait for another program to exit with an undefined runtime and continue to work if there is no exit by the time the program ends.

Here is this section of code

 my $pid = open (my $input, '-|', "$prog $args") or push @errors, "A failute has occurred in $prog $args"; if(not @errors){ while (<$input>){ #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\""; } 

note: $fh is my file handler used to write to the log file, and @errors used for internal error messages in my program.

EDIT: One of the problems that I encountered while trying Proc :: Reliable is that it seems to have consequences after STDOUT and STDERR , and I will need to fix them after each run. This leads to another problem in my code. I work in parallel, and any change to STDOUT and STDERR affects all threads (at least on Windows).

IO :: CaptureOutput has the same problem for me, but it tries to fix the STDOUT and STDERR errors internally and causes the following error:

 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 
+7
source share
2 answers

If you start from a POSIX-like shell, then note 2>&1 sends the standard error to the same place as the standard output:

 some-program-to-be-logged 2>&1 | perl logger.pl -o /chosen/log.file 

Both standard output and standard error are sent to the standard input of the Perl script log.

The input loop in the logger script will hang until a read input has been entered, or until all processes with an open write channel have closed the handset (usually because of their output).

+1
source
+1
source

All Articles