Search code examples
rubyloopszipdelay

Ruby - Delay the ruby program till the shell command execution completed


I am using shell command to zip file in ruby. Then I am uploading the zipped file to server. when I use it in a loop like:

dump_files.each do |dump_file|
  Open3.popen3("zip #{zip_file}  #{dump_file}")
end

And upload, the last file in the dump_files array is not present in the uploaded zipfile but it present in the local file.

I think it happens because of the time delay to zip the file. How can I delay my ruby execution till the zip command execution complete?


Solution

  • Shouldn't that be:

    `zip "#{zip_file}"  "#{dump_file}"`
    

    (in other words, you're not zipping at all?)