如何同时将程序的输出定向到控制台和日志文件?

发布于 2024-07-29 16:29:06 字数 140 浏览 3 评论 0原文

如何同时将输出打印到终端和文件?

$ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青衫儰鉨ミ守葔 2024-08-05 16:29:07

perl foo.pl | tee fooout.txt

perl foo.pl | tee foout.txt

庆幸我还是我 2024-08-05 16:29:07

实用程序 tee 将执行此操作。

The utility tee will do that.

々眼睛长脚气 2024-08-05 16:29:07

请参阅 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.

左岸枫 2024-08-05 16:29:07

或者您可以将其通过管道传输到 perl 程序中以打印到屏幕和日志文件(也就是说,如果您不在 Unix 上或没有 tee 程序)

perl foo.pl | perl myPipe.pl myFile.txt

其中数据被捕获到 myFile.txt 和

myPipe.pl 中

#
open OUTFILE,">$ARGV[0]" or die "Unable to open file: $ARGV[0]\n";

while(<>)
{
    print;
    print OUTFILE;
}
close OUTFILE;

这从 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

#
open OUTFILE,">$ARGV[0]" or die "Unable to open file: $ARGV[0]\n";

while(<>)
{
    print;
    print OUTFILE;
}
close OUTFILE;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文