From: Jp Hastings-spital Date: 2009-03-21T03:05:19+09:00 Subject: Re: Wrapping applications in Ruby IO.popen method with io.each "\r" works spot on! Thanks so much! Haven't tried working with Open3.popen3 yet, I may try reinstalling the gem. Thanks for your replies, you've been patient and very helpful! Robert Klemme wrote: >> %\rEncoding: task 1 of 1, 0.18 %\rEncoding: task 1 of 1, 0.23 % > If you have "\r" as line terminator, you can do the reading like this > > io.each "\r" do |line| > # do whatever with line > end This makes it work beautifully! > > e.g. > > robert@fussel ~ > $ ruby -e '3.times {|i| printf "%03d\r", i}' | ruby -e > '$stdin.each("\r") {|l| p l}' > "000\r" > "001\r" > "002\r" > > robert@fussel ~ > $ > >> $ cat wrapper.rb >> input = "input.avi" >> output = "output.mp4" >> IO.popen("/usr/local/bin/HandBrakeCLI -i \"#{input}\" -o \"#{output}\"") >> { |stdout| >> p stdout.read > > See above. > >> } >> >> This prints nothing! Am I right in thinking that the popen block gets >> called every time a \n character is captured by the pipe? (Your >> 'counting.rb' uses \n rather than \r - and works) Any ideas (other than >> say, passing the output through sed or something similar)? >> >> Thanks again, JP > > Note that the proper line reading (as suggested above) still does not > help if the other program internally buffers IO. > > Kind regards > > robert -- Posted via http://www.ruby-forum.com/.