How to zip stderr message to a core file!

N

news.hinet.net

open STDERR, "../tmp/core" or die " Can't write to ../tmp/core : $! \";

1.How to zip stderr and insert the message to a zip file(core)?
2.Could i add some string to stderr?? Ex: date info
 
I

Ilmari Karonen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,415
Latest member
PeggyCramp

Latest Threads

Top