in reply to Retrieving the Progress of a Command

You can use open to connect to a command with a pipe and get its output. Commandline progress bars work by printing the carriage return character ("\r"), to set the cursor back to the start of line and overwriting the text. To capture each update in progress, you can set the input record separator to "\r".
use feature qw(say); my $rsync_command = 'rsync ... --progress'; open my $RSYNC, '-|', $rsync_command or die "Failed to start rsync: $! +"; local $/ = "\r"; while (<$RSYNC>) { if (/\A\s/) { # progress lines start with whitespace say 'Progress: ', $_; } else { print 'File: ', $_; # file lines have newlines at the end } } close $RSYNC;
The code to differentiate between a filename and a progress line could be upgraded a bit but this is the general approach I would use to monitor progress bars.

Replies are listed 'Best First'.
Re^2: Retrieving the Progress of a Command
by hoyt (Acolyte) on Sep 13, 2016 at 22:39 UTC
    That makes sense. I'll try to adapt that and see how I can make it work here. Thanks!