بحاجة إلى مؤشر تقدم لأمر نظام Perl () باستخدام T: R: G وزارة الدفاع
-
15-11-2019 - |
سؤال
أريد مؤشر تقدم يأخذ إخراج بيرل giveacodicetagpre.
ولكل إخراج سطر إلى Stdout من الأمر "إجراء"، أريد إخراج نقطة كمؤشر تقدم.لسوء الحظ، أنا أستخدم المصطلح :: Readline :: GNU Perl Mod.
كيف أعيد توجيه Stdout لالتقاط الخطوط وحساب الأمر كأمر عمل يعمل؟
المحلول
#!/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