For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > July 2004 > How to zip stderr message to a core file!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to zip stderr message to a core file!
news.hinet.net

2004-07-23, 8:56 am


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






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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com