Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Retrieving the Progress of a Command

by kroach (Pilgrim)
on Sep 13, 2016 at 21:14 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found