Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: how do i redirect STDOUT, STDIN, or STDERR to a FILE?

( #11103=categorized answer: print w/ replies, xml ) Need Help??

Q&A > input and output > how do i redirect STDOUT, STDIN, or STDERR to a FILE? contributed by perlmonkey

The easist way to do this is to use fdopen from IO::Handle:
use IO::Handle; open INPUT, '<', "input.txt" or die $!; open OUTPUT, '>', "output.txt" or die $!; open ERROR, '>', "error.txt" or die $!; STDIN->fdopen( \*INPUT, 'r' ) or die $!; STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!; STDERR->fdopen( \*ERROR, 'w' ) or die $!; # prints to output.txt: print "Hello Output File\n"; # reads everything from input.txt and prints it to output.txt: print <>; # prints to error.txt: warn "Hello Error File\n";

Comment on Answer: how do i redirect STDOUT, STDIN, or STDERR to a FILE?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2015-07-04 00:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls