开发者

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

开发者 https://www.devze.com 2023-03-24 15:44 出处:网络
I am using shell command to zip file in ruby. Then I am uploading the zipped file to 开发者_StackOverflowserver.

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}`
0

精彩评论

暂无评论...
验证码 换一张
取 消