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

后端 未结 6 1583
北海茫月
北海茫月 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:34

    for foo in bar
      out = IO.popen(cmd_foo)
      out.readlines
    end
    IO.popen(another_cmd)
    

    Reading the output to a variable then calling out.readlines did it. I think that out.readlines must wait for the process to end before it returns.

    Credit to Andrew Y for pointing me in the right direction.

提交回复
热议问题