How to you redirect stdout to a file? I want to do something like:
Code:open(OUTPUT, ">outfile.txt"); setstdout(OUTPUT); print "hello outfile.txt"; close(OUTPUT);
How to you redirect stdout to a file? I want to do something like:
Code:open(OUTPUT, ">outfile.txt"); setstdout(OUTPUT); print "hello outfile.txt"; close(OUTPUT);
Are you sure you want to redirect stdout? You could just print to the file
But if you want to redirect STDOUT, STDIN, or STDERR, just open the file and assign it to that handleCode:open(OUTPUT, ">outfile.txt"); print OUTPUT "hello outfile.txt\n"; close(OUTPUT);
Code:open(STDOUT, ">outfile.txt"); print "hello outfile.txt\n";
This works for me:
The only thing is, I'm not 100% sure how to bring STDOUT to point back to itself originally.Code:#! perl open (STDOUT, ">stdout.txt"); print "what what!"; close (STDOUT);
edit: Maybe this might help; some more elegant solutions http://perlmonks.thepen.com/11007.html
edit2: And I agree, I have no idea why you would want to redirect STDOUT.