Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

by perlmonkey (Hermit)
on May 11, 2000 at 07:02 UTC ( #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? - Answer 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";

Log In?

What's my password?
Create A New User
[hippo]: On my tab key the left pointing arrow is directly above the right-pointing arrow (and they are each pointing at a vertical line). It's a UK keyboard.
[Discipulus]: choroba thanks.. now i understand: like find the tresaure.. but in this case seems true: no one noticed
[Discipulus]: Happy-the-monk every Eatalian understand what ctrl+shift+tab means: we just have different names for # and @ ('cancelletto' and 'chiocciola')

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-11-21 10:20 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (297 votes). Check out past polls.