使用T:R mod需要一个perl system()命令的进度指示符
-
15-11-2019 - |
题
我想要一个perl 的输出的进度指示器
system('make')
.
以及从make命令输出到stdout的每个行,我想将点作为进度指示器输出。不幸的是,我正在使用这个词:: readline :: gnu perl mod。
如何将stdout重定向以捕获并计算Make命令运行时的行?
解决方案
#!/usr/bin/perl
my $command = "make";
open (my $cmd, "$command |");
while(<$cmd>){
print ".";
}
print "\n";
其他提示
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";}
不隶属于 StackOverflow