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 开发者_StackOverflowserver. 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?
Shouldn't that be:
`zip "#{zip_file}" "#{dump_file}"`
(in other words, you're not zipping at all?)
Using `` instead of popen3 will fix the issue
replace
Open3.popen3("zip #{zip_file} #{dump_file}")
with
`zip #{zip_file} #{dump_file}`
精彩评论