Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://3238]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-23 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found