如何同时将程序的输出定向到控制台和日志文件?
如何同时将输出打印到终端和文件?
$ perl foo.pl > foout.txt
不允许我看到实时进程。
有什么方法可以实时查看输出过程并最终在文件上获取屏幕输出?
How can I print the output to terminal and file at the same time?
$ perl foo.pl > foout.txt
does not allow me to see live process.
Is there any way I can see the output process real time and getting at the end the output of the screen on a file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
perl foo.pl |
tee
fooout.txt
perl foo.pl |
tee
foout.txt
实用程序 tee 将执行此操作。
The utility tee will do that.
请参阅 IO::Tee。 该模块将允许您在程序中通过细粒度控制有选择地执行此操作(还有一个不太成熟的模块,称为 File::Tee 曾经对我有用过,但我不会推荐它用于任何严肃的项目)。
另请参阅 Log4perl,了解对记录内容、记录位置和记录方式的真正细粒度控制。
对于从命令行的一次性使用,正如其他人所建议的,您当然可以使用命令行实用程序
tee
(如果您有权访问它)。See IO::Tee. This module will allow you to do this selectively with fine grained control within your program (there is also a less mature module called File::Tee which worked for me once but I would not recommend that for any serious project).
See also Log4perl for really fine grained control over what gets logged where and how.
For one off usage from the command line, as others have recommended, you can, of course, utilize the command line utility
tee
if you have access to it.或者您可以将其通过管道传输到 perl 程序中以打印到屏幕和日志文件(也就是说,如果您不在 Unix 上或没有 tee 程序)
perl foo.pl | perl myPipe.pl myFile.txt
其中数据被捕获到 myFile.txt 和
myPipe.pl 中
这从 STDIN 读取一行输入并将其打印到屏幕,然后打印到文件。 当到达末尾时,它将关闭文件
Or you could pipe it into a perl programs to print to the screen and a log file (that is if you are not on Unix or have a tee program)
perl foo.pl | perl myPipe.pl myFile.txt
where the data is captureed to myFile.txt and
myPipe.pl is
This reads a line of input from STDIN and prints it to the screen and then to the file. When the end is reached, it will close the file