Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ruby中使用backtick获得子流程的连续输出_Ruby_Subprocess_Stdout - Fatal编程技术网

如何在ruby中使用backtick获得子流程的连续输出

如何在ruby中使用backtick获得子流程的连续输出,ruby,subprocess,stdout,Ruby,Subprocess,Stdout,我有一个ruby应用程序,它使用backtick作为子进程执行ant。这项工作没有任何问题。当我放置ant时,ruby会等待子进程ant完全完成,然后将输出打印到stdout。如何让ruby连续打印子流程的输出?您可以使用IO.popen IO.popen("ant") do |output| while line = output.gets do # ... maybe puts line? something more interesting? end en

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

您可以使用
IO.popen

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