Re: Copy STDOUT and STDERR to logfile and also display to screen
by japhy (Canon) on Aug 10, 2005 at 17:38 UTC
|
| [reply] |
|
|
No such module, that I can find. I think you meant to say IO::Tee.
--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/;
map{y/X_/\n /;print}map{pop@$_}@/for@/
| [reply] [d/l] |
Re: Copy STDOUT and STDERR to logfile and also display to screen
by pboin (Deacon) on Aug 10, 2005 at 17:36 UTC
|
You might want to look into man tee if you're on a *nix system. Description: Copy standard input to each FILE, and also to standard output.
Don't know if it works w/ STDERR though...
| [reply] [d/l] |
Re: Copy STDOUT and STDERR to logfile and also display to screen
by kirbyk (Friar) on Aug 10, 2005 at 18:05 UTC
|
In addition to the more generic advice, if you're on a unix system, most people just do 'tail -f filename'. The 'tail' command gives you the last lines of a file, and the -f argument 'streams' new input into the screen. You can specify multiple files and it will intersperse changes sensibly.
| [reply] |
Re: Copy STDOUT and STDERR to logfile and also display to screen
by sk (Curate) on Aug 10, 2005 at 17:51 UTC
|
If you are on non UNIX platform i wrote this small script that does tee - useful with pipes: Creating an outputfile and processing it at once
tee is useful when you cannot change the script that was given to you and you want to save and view. But if you are the author of the script why can't a simple print statement work?
for example -
if ($error) {
print STDERR ("Error: $errmsg\n");
print ERRLOG ("Error: $errmsg\n");
} else {
print ("Output: $outstr\n");
print CLEANLOG ("Output: $outstr\n");
}
Of course if you if you are interpolating the string inside print I would probably first do that in a variable and use it inside print to avoid interpolating twice
Am i missing somethign here?
| [reply] [d/l] [select] |
|
|
sub my_print { print @_; print CLEANLOG @_ }
sub err_print { print STDERR @_; print ERRLOG @_ }
--
We're looking for people in ATL
| [reply] [d/l] |
|
|
Thanks for the tip on the sub.
regarding your other comment: It works, but now you've got two copies of every message
Could you please explain what do you mean by copy? it writes the same msg twice but it does it in two different places...the output on the screen will not have dups and the output in the log will not have dupliactes...
if you say it is inefficient to do it this then i would agree but i am not sure whether i understand the term "copy" there.
thanks
SK
| [reply] |
|
|
|
|
Re: Copy STDOUT and STDERR to logfile and also display to screen
by salva (Canon) on Aug 11, 2005 at 09:12 UTC
|
on Unix, pipeing the output to a new forked process is the only way that would work in any case:
select STDERR;
$|=1
unless (open STDERR, '|-') {
eval {
open ERRLOG, ">/tmp/errlog" or die;
while(<>) {
print ERRLOG $_;
print STDERR $_;
}
};
exit(0);
}
# repeat for STDOUT
| [reply] [d/l] |
|
|
Sorry guys, I should have mentioned I am doing this on a Win32 system at the moment. The Unix stuff will come in handy though.
| [reply] |