in reply to Re: Capture wget progress bar
in thread Capture wget progress bar
Of course the error handling for it like that is not too great.sub wget { my $file = shift; $SIG{INT} = sub { unlink $log_f; exit }; if (my $pid = fork) { system "wget -o $log_f --progress=bar:force -c $file"; } else { die "cannot fork: $!" unless defined $pid; } sleep 1 until -f $log_f; open LOG, $log_f or die "Couldn't open '$log_f': $!\n"; my ($pos, $length, $status); while (1) { for ($pos = tell LOG; $_ = <LOG>; $pos = tell LOG) { s/^\s+//; if (/^Length: ([\d,]+)/) { print "Downloading: $file [$1] bytes.\n"; } elsif (/^\d+%/) { print "$_\r"; $status = 'downloading'; } elsif (defined $status eq 'downloading' and !/^\d+%/) { unlink $log_f; print "\n"; last; } } sleep 1; seek LOG, $pos, 0; } }
|
---|