Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Capture Error Messages to a File? How?

by nickcave25 (Acolyte)
on Feb 09, 2000 at 08:59 UTC ( [id://3238] : perlquestion . print w/replies, xml ) Need Help??

nickcave25 has asked for the wisdom of the Perl Monks concerning the following question:

I know the way to redirect the output of, say, a perl program to a textfile as follows:

%perl5 -w perlprog.cgi >> textfile.txt


But how do I redirect to a textfile (for later review) the many error messages that often cascade across my screen during the debugging process (lost for ever for a lack of a ``scrollup'' facility within my simple telnet client) never to be seen again.

Any suggestions?

TIA!

Replies are listed 'Best First'.
Re: Capture Error Messages to a File? How?
by Anonymous Monk on Feb 09, 2000 at 16:55 UTC
    If you want to redirect the err messages (ie STDERR) to *another* log file then use the following:
    jamie@lillith ~ $ perl -w perlprog.cgi >> textfile.txt 2> logfile
    However if you want to direct STDERR to STDOUT (the output from the perl prog) then do the following:
    jamie@lillith ~ $ perl -w perlprog.cgi > logfile 2>&1
Re: Capture Error Messages to a File? How?
by repson (Chaplain) on Dec 04, 2000 at 11:51 UTC
    The other way of accomplishing this task in doing it in perl. You can include this at the beginning of your document: open STDERR,'> logfile' or die "Can't write to logfile: $!\n"; Or for compile time errors as well: BEGIN { open STDERR,'> logfile' or die "Can't write to logfile: $!\n"; } These techniques also allow redirection of errors in situations where you can't use shell features, such as in CGI scripts.
Re: Capture Error Messages to a File? How?
by nickcave25 (Acolyte) on Feb 09, 2000 at 17:42 UTC
    Thanks... I'll try it/them!
Re: Capture Error Messages to a File? How?
by Anonymous Monk on Feb 10, 2000 at 16:28 UTC
    Run your script within the Emacs shell. In Emacs, type the command: M-x shell (See the docs for shell-specific hotkeys.) This technique makes it easier not only to view the results, but also to kill/paste the results between other files.