1

I want to extract zip files and delete them when they are extracted. Googling tells me that the easiest way to unzip files in Ruby is to execute them with unzip filename.zip. My next step is to delete the zip file.

The second step happens so fast that the shell command unzip does not have a chance to even see the file before it is deleted. It errors out saying

"unzip:  cannot find either filename.zip or filename.zip.zip."

I just want to have the unzip... command complete before continuing execution of the ruby script. I want it to block synchronously. Is there a way to do that? I cannot use sleep because I cannot estimate how long it will take.

2
  • 2
    Would be a good idea to show us your code. Commented Aug 28, 2012 at 1:36
  • 2
    Please post your actual code. Commented Aug 28, 2012 at 1:36

1 Answer 1

4

The usual ways to run an external program in ruby are synchronous so there should be no problem.

Try

`unzip`

or

system("unzip")

or

system("unzip x && rm x")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I think the system("unzip x && rm x") will work. I already solved my problem by using the rubyzip library to unzip. But if I had to execute a shell command, I suppose your trick will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.