DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Perl: Redirect STDERR In A Script

  • submit to reddit
        Redirect STDERR to a file from within a script.

use IO::Handle;

# Redirect the STDERR screen to a log file
open EOUT, ">/path/to/log/file" or die $!;
STDERR->fdopen(\*EOUT, "w") or die $!;

# Redirect the STDOUT screen to a log file
open SOUT, ">/path/to/log/file" or die $!;
STDOUT->fdopen(\*SOUT, "w") or die $!;

# Something useful here

close EOUT;
close SOUT;

# End of program