简体   繁体   English

如何将Windows命令提示符下发出的命令的Perl脚本输出重定向到文本文件

[英]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: 我是Perl的新手,我通过执行以下操作在Windows 7的CommandPrompt对话框中执行.pl文件:

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? 除了在CommandPrompt对话框中看到输出之外,还有一种方法可以将输出重定向到文本文件吗?

Any help/direction would be appreciated. 任何帮助/方向将不胜感激。 Regards. 问候。

If you append '> filename.txt' to your line, it will output the results to a file instead. 如果将'> filename.txt'附加到您的行,它会将结果输出到文件中。 If you want to do both, there is apparently the wintee utility at http://code.google.com/p/wintee/ . 如果您想同时执行这两项操作,则可以在http://code.google.com/p/wintee/上找到 wintee实用程序。 If it is similar to UNIX tee, than using it should only require you to append '| 如果它类似于UNIX tee,那么使用它应该只需要你追加'| tee filename.txt' to your line. tee filename.txt'到你的专线。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM