0

I'm trying to write a Ruby script that goes into each sub-directory in a directory, and then executes several commands. I am using the System() command to execute some of them. Based on the documentation, I thought that System() should wait for a subprocess to end before proceeding further. However, it does not appear to do so. This is a simplified version of my script:

Dir.glob("**/") do |subdir|
     Dir.chdir(subdir) do
        system("gunzip *paired.fastq.gz")
     end
end

I want it to run gunzip on one or all of the appropriate files in the first subdirectory, and once these gunzip processes are ended, then go to the next subdirectory and so on. But right now, it just creates gunzip processes for files in all of the subdirectories simultaneously. Am I misunderstanding the System() documentation? Is there any other command I should use instead ?

Thanks !!!

  • I'm unable to reproduce this behavior. If you execute `Dir.glob("*/") { system 'sleep 1; printf "hola"'}` in an irb console, what happens? does it hangs? – yeyo Oct 16 '15 at 21:07
  • @yeyo: It returns the following: hola=> nil – user2566225 Oct 19 '15 at 20:19

0 Answers0