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 f
open my $fh, '>', $file;
defined(my $pid = fork) or die "fork: $!";
if (!$pid) {
open STDOUT, '>&', $fh;
# do whatever you want
...
exit;
}
waitpid $pid, 0;
print $? == 0 ? "ok\n" : "nok\n";