Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get continuous output of subprocess started using backtick in ruby

I have a ruby application that executes ant as a subprocess using backtick. This works without any problems. When I do puts ant, ruby waits for the subprocess, ant, to finish completely and then prints the output to stdout. How do I get ruby to print the output from the subprocess continuously?

like image 818
Bala Avatar asked Jul 01 '09 22:07

Bala


1 Answers

You could use IO.popen.

IO.popen("ant") do |output| 
    while line = output.gets do
        # ... maybe puts line? something more interesting?
    end
end
like image 123
Sarah Mei Avatar answered Sep 16 '22 16:09

Sarah Mei