http://qs1969.pair.com?node_id=749171

macguide has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to handle output from another program that does not use line breaks in some of it's output?

I am piping Rsync's output to a perl script so that I can see Rsync's file transfers as they happen. The problem is that Rsync outputs the file transfer progress without line breaks, and only sends a line break after each transfer is complete. I think Rsync does this so that when you run in from the command line the percentage number just changes instead of filling your terminal screen with lots of lines. So I want to be able to view the <STDIN> data before the final line break is sent. Any ideas?

Or should I scrap this idea and just send the output of Rsync to a log file and have Perl evaluate the tail of the log file every few seconds?

Thanks!

Replies are listed 'Best First'.
Re: using STDIN that has no line breaks
by ig (Vicar) on Mar 08, 2009 at 23:30 UTC
Re: using STDIN that has no line breaks
by Illuminatus (Curate) on Mar 08, 2009 at 23:51 UTC
    You could also experiment with changing $RS from newline to carriage-return. The 'precentage progress' that continually updates the same line is done via carriage-return. However, I don't know if you get the CR at the 100% mark.
Re: using STDIN that has no line breaks
by Anonymous Monk on Mar 08, 2009 at 22:07 UTC
Re: using STDIN that has no line breaks
by jplindstrom (Monsignor) on Mar 09, 2009 at 13:41 UTC
    What other people said to solve your specific problem.

    Or in general: look at the variable $/ (the input record separator, newline by default. This influences Perl's idea of what a "line" is) in perlvar (perldoc perlvar from the command line).

    /J

Re: using STDIN that has no line breaks
by macguide (Initiate) on Mar 09, 2009 at 16:47 UTC
    Thanks everyone. I ended up setting $/ = "\r" and that worked great.

    I will also look into File::Rsync & File::RsyncP for greater control.