Melinda
Melinda

Reputation: 1531

How to redirect the Perl script output from command issued in windows command prompt to text file

I am new to Perl and I am executing a .pl file within the CommandPrompt dialog box in Windows 7 by doing the following:

c:\perlscripts\runReport.pl 5 

In addition to seeing the output in the CommandPrompt dialog box is there a way that I can redirect the output to a text file as well?

Any help/direction would be appreciated. Regards.

Upvotes: 1

Views: 2224

Answers (2)

Krishnachandra Sharma
Krishnachandra Sharma

Reputation: 1342

Instead of printing the output in command line. You can write the output in a file.

# Opening file to write the program's output. 
open(FH, ">myFile.txt") or die "Cannot open myFile.txt";

# include module to dump output.
use Data::Dumper;
print FH Dumper(@output);

close FH;

Else you can write like this:

perl my_script.pl > myFile.txt

Upvotes: 0

tohava
tohava

Reputation: 5412

If you append '> filename.txt' to your line, it will output the results to a file instead. If you want to do both, there is apparently the wintee utility at http://code.google.com/p/wintee/. If it is similar to UNIX tee, than using it should only require you to append '| tee filename.txt' to your line.

Upvotes: 4

Related Questions