Need a progress indicator for a Perl system() command using T:R:G mod

大城市里の小女人 提交于 2019-12-21 20:00:51

问题


I want a progress indicator that takes the output of a Perl

   system('make')

and for each line output to STDOUT from the make command, I want to output a dot as a progress indicator. Unfortunately, I'm using the Term::ReadLine::Gnu Perl mod.

How do I redirect STDOUT to capture and count the lines as the make command is running?


回答1:


#!/usr/bin/perl

my $command = "make";

open (my $cmd, "$command |");
while(<$cmd>){
  print ".";
}
print "\n";



回答2:


make >& >(while read f; do echo -n .; done; echo)

Obviously this is a shell solution, but a dot as a progress indicator is a dot.

You could of course stick a tee in there to save a copy of the make to file in case of problems.

Since you didn't seem to like (neither upvoted or accepted) the shell solution for some unexplained reason, here is a pure perl one:

if (open(X,"make|")) { local($|)=1; while(<X>) { print "."; } close(X); print "\n";}


来源:https://stackoverflow.com/questions/6052345/need-a-progress-indicator-for-a-perl-system-command-using-trg-mod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!