I asked a question originally
here, and rec'd some good input. I am posting this as a second thread because I view it as a seperate question, I hope I am not wrong in doing so. Combining the advice in that thread with some of my code, I came up with the following method to copy STDERR and STDOUT on win32 systems. I am no guru by any means and am open to any advice and/or criticism on this method.
#### Use cpprint in place of print ####
cpprint("HELLO OUTPUT\n");
#### WARN STATEMENTS WILL BE WRITTEN TO STDOUT AND ERRFILE ####
warn "HELLO ERR FILE";
#### DIE STATEMENTS WILL BE WRITTEN TO ERRFILE, SINCE DIE EXECUTES NO
+MATTER WHAT IS IN THE INIT DIE STATEMENTS WILL GO TO STDERR ANYWAY ##
+##
die "HELLO DEATH\n";
INIT {
my $outfile = "myoutfile.out";
my $errfile = "myerrfile.err";
open(ERRFILE,'>>', "$errfile") or die "Could not open error file $
+errfile $!\n";
open(OUTFILE,'>>', "$outfile") or die "Could not open error file $
+outfile $!\n";
$SIG{'__DIE__'} = \&ondie;
$SIG{'__WARN__'} = \&onwarn;
}
END {
close ERRFILE;
close OUTFILE;
}
sub ondie {
my $date = localtime(time);
print ERRFILE "$date\t@_\n";
}
sub onwarn {
print "WARNING: @_\n";
my $date = localtime(time);
print ERRFILE "$date\tWARNING: @_\n";
}
sub cpprint{
my $date = localtime(time);
print OUTFILE "$date\t@_";
print @_;
}
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.