How to wait for process to finish using IO.popen?

后端 未结 6 1586
北海茫月
北海茫月 2020-12-29 06:14

I\'m using IO.popen in Ruby to run a series of command line commands in a loop. I then need to run another command outside of the loop. The command outside of t

6条回答
  •  孤城傲影
    2020-12-29 06:22

    I suggest you use Thread.join to synchronize the last popen call:

    t = Thread.new do
        for foo in bar
           IO.popen(cmd_foo)
        end
    end
    
    t.join
    
    IO.popen(another_cmd)
    

提交回复
热议问题