How can I redirect standard output to a file in Perl?

Mike picture Mike · May 25, 2010 · Viewed 29.1k times · Source

I'm looking for an example of redirecting stdout to a file using Perl. I'm doing a fairly straightforward fork/exec tool, and I want to redirect the child's output to a file instead of the parents stdout.

Is there an equivilant of dup2() I should use? I can't seem to find it

Answer

ivans picture ivans · May 25, 2010

From perldoc -f open:

open STDOUT, '>', "foo.out"

The docs are your friend...