如何在Perl中反引号中的输出刷新? [英] How to flush output in backticks In Perl?

查看:107
本文介绍了如何在Perl中反引号中的输出刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这个perl应用程序:

If I have this perl app:

print `someshellscript.sh`;

可以打印很多东西,并且需要很长时间才能完成,我该如何在在shell脚本执行的中间?

that prints bunch of stuff and takes a long time to complete, how can I print that output in the middle of execution of the shell script?

看起来像Perl只会在完成时打印someshellscript.sh结果,有没有办法在执行过程中刷新输出?

Looks like Perl will only print the someshellscript.sh result when it completes, is there a way to make output flush in the middle of execution?

推荐答案

您可能想做的事情是这样的:

What you probably want to do is something like this:

open(F, "someshellscript.sh|");
while (<F>) {
    print;
}
close(F);

这将运行 someshellscript.sh 并打开一个读取其输出的管道。 while 循环读取脚本生成的每一行输出并进行打印。有关更多信息,请参见打开文档页面。

This runs someshellscript.sh and opens a pipe that reads its output. The while loop reads each line of output generated by the script and prints it. See the open documentation page for more information.

这篇关于如何在Perl中反引号中的输出刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆