Hello all,
I'm somewhat new to IPC and about to go crazy. In my program there is a LOG handle for recording what happens. In one subroutine where I want to be really meticulous with how I handle errors, I redirect STDERR from a pipe into a file, err.log. If upon successful pipe opening there is content in err.log, I want to: A)print a warning to the standard log B)exit the entire program, while printing "Killed" to the screen.
Well, with the code below, I get err.log populated, but nothing is printed to the screen. And no, "Killed" is not printed to err.log either. Worst of all, the die, if it's being executed at all, seems to only be exiting the subroutine, because print statements from other_code() are printed to my standard log.
I'm getting really REALLY frustrated with the intricacies of pipes, handle redirection/selection/closing, and autoflushing, having worked on this for the last few hours. Could someone PLEASE sort me out. Thanks so much. Below is skeleton code without all my failed experimentation, just so you can see what my intent is.
open LOG ">>std.log" or die $!;
im_missing_something_here();
other_calls();
close LOG;
sub im_missing_something_here {
open STDERR, ">>err.log" or die $!;
# Perl can run the shell #
if (open(PIPE, "$cmd <$tempfile |")) {
# but there is a message in STDERR #
if (-s './err.log') {
print LOG "ERROR:see err.log, exiting..\n";
close STDERR;
die "Killed.\n"; #to default STDERR is intent
}
...
}