in reply to Progress Bar Between Multiple System Calls
If you just want to show that progress is being made, rather how far things have got, monitoring the size of the output file is easy using a thread:
Added a sleep to the display loop to prevent it from running away with the cpu. Using Win32::Sleep( 500 ); or selectundef, undef, undef, 0.5 might be better?
#! perl -slw use strict; use threads; use threads::shared; my $outfile = 'output.txt'; unlink $outfile ; my $done:shared = 0; async{ system("dir /s > $outfile"); $done =1; }; sleep 1 until -e $outfile; printf STDERR "\r%d\t", -s( $outfile ) and sleep 1 until $done; print STDERR 'Output complete';
If you can estimate the size of the output file--for example in your second command, there may be some rough correspondance between the size of the output from the first and that from the second--then you can easily convert the raw numbers into an estimated percentage. If your percentage runs over by a few percent and finishes at 105%, you'll be forgiven provided that you a) indicate that it is an estimate; b) it proves reasonably accurate.
Alternatively, add 10% to your final size estimate. When the command finishes 'early' at say ~90%, no one will complain :)
Wrapping that up into a function that takes the command, the path of the output file and an estimate of the final size is left as an exercise.
|
|---|