in reply to Printing Warning Messages Into a File

The shorthand to do so in bash or another console that supports it is:
$ perl mycode.pl &> debug.txt
or the more explicit:
$ perl mycode.pl 2>1 1> debug.txt
Both of these redirect streams STDERR and STDOUT to a file.

Also see:
open 'STDERR', '>', './File' or die $!;
and:
open 'STDERR', '>', './File' or die $!;
Which would make it so the streams are rediected inside of the program rather than by the console.


Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re^2: Printing Warning Messages Into a File
by sauoq (Abbot) on Oct 28, 2005 at 02:35 UTC
    $ perl mycode.pl 2>1 1> debug.txt

    No, that's broken in two ways. First, you are missing an ampersand... (which means your errors are going into the file ./1.) After you fix that, you'll still see the error. Pop quiz: Why?

    Order matters. You have to redirect stdout before stderr... because otherwise stderr points to the old stdout while stdout points to the file.

    -sauoq
    "My two cents aren't worth a dime.";
    
      God, I always wondered why that was and I keep getting it wrong. (the part in the spoiler I mean) But your explanation makes sense!