Over a million developers have joined DZone.

Perl: Redirect STDERR In A Script

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


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}