Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

using STDIN that has no line breaks

by macguide (Initiate)
on Mar 08, 2009 at 22:04 UTC ( #749171=perlquestion: print w/replies, xml ) Need Help??

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?


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).


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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://749171]
Approved by Perlbotics
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2023-03-31 12:18 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (75 votes). Check out past polls.