Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Retrieving the Progress of a Command

by kroach (Pilgrim)
on Sep 13, 2016 at 21:14 UTC ( #1171695=note: print w/replies, xml ) Need Help??

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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1171695]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-10-26 08:08 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (250 votes). Check out past polls.