| Ilmari Karonen 2004-07-23, 8:56 pm |
| On 2004-07-23, news.hinet.net <luke@program.com.tw> wrote:
>
> 1.How to zip stderr and insert the message to a zip file(core)?
"Zip"? Like this?
open STDERR, '|gzip >>../tmp/core' or die "Can't redirect stderr: $!\n";
If you want to put stderr later the way it was, you need to dup it
first:
open TMPERR, '>&', \*STDERR or die "Can't dup stderr: $!\n";
open STDERR, '|gzip >>../tmp/core' or die "Can't redirect stderr: $!\n";
# ... do stuff ...
open STDERR, '>&', \*TMPERR or die "can't restore stderr: $!\n";
> 2.Could i add some string to stderr?? Ex: date info
You can do this by opening a pipe to (a fork of) yourself:
defined(my $pid = open STDERR, '|-') or die "Can't fork: $!\n";
if (!$pid) {
while (<STDIN> ) {
print STDERR "[".gmtime()." GMT] $_";
}
exit;
}
Combining the two solutions is left as an exercise.
--
Ilmari Karonen
If replying by e-mail, please replace ".invalid" with ".net" in address.
|