1

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for your quick response. I actually tried that but here is the issue. In the commandprompt dialog box I'm showing a stack trace that is printing out but it does not print to the text file. Any suggestions? Thanks.
@Melinda It's probably going to STDERR, so you could send both to the same place by appending '2>&1' to the end of your line.
@Melinda: It's not a dialogue box - it's a window.
Thanks Borodin. I appreciate the clarification.
@Melinda, it would actually be 'runReport.pl 4 > melinda.txt 2>&1', but if you are going to use tee like tohava pointed out, it would be 'runReport 4 | tee melinda.txt 2>&1'
|
0

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

1 Comment

You should recommend using 3-arg open instead of 2-arg. modernperlbooks.com/mt/2010/04/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.