如何在ruby中使用反引号开始连续输出子进程

时间:2022-02-11 00:06:54

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?

我有一个ruby应用程序,使用反引号执行ant作为子进程。这没有任何问题。当我放置ant时,ruby等待子进程,ant,完全完成然后将输出打印到stdout。如何让ruby连续打印子进程的输出?

1 个解决方案

#1


10  

You could use IO.popen.

你可以使用IO.popen。

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

#1


10  

You could use IO.popen.

你可以使用IO.popen。

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