views:

523

answers:

2

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?

A: 

use system()

Ben Hughes
+4  A: 

You could use IO.popen.

IO.popen("ant") do |output| 
    while line = output.gets do
        # ... maybe puts line? something more interesting?
    end
end
Sarah Mei