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
}
...
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.