From: Shashank Date Date: 2002-08-20T11:29:23+09:00 Subject: thread control I am trying to write a ruby script (Ruby 1.7.2 mswin32) which does the following: 1. Spawn a few threads (say 3, for the time being) each of which invokes an external program using the backquotes. 2. Let the main thread continue till either all the threads are done executing OR some external event occurs (like deletion of a file by another program). I cannot seem to make it work (may be because thread implementation in Ruby is not "native" ?). Please help. TIA, -- Shanko # Here is my broken script: # ------------------------------------------------------ cmds = [ "ping 10.0.0.0 -n 30 -w 1000 > NUL", "ping 10.0.0.0 -n 60 -w 1000 > NUL", "ping 10.0.0.0 -n 90 -w 1000 > NUL" ] out = [] threads = [] for c in cmds threads << Thread.new(c) { |myCmd| puts "#{myCmd}" out << `#{myCmd}` } end puts threads.length.to_s + ' threads running' begin i = 0 threads.each { |t| i += 1 if t.stop? } puts `echo %TIME%` b = File.exists?("C:\\junk\\tmp_0.txt") puts i.to_s + ':' + File.mtime("C:\\junk\\tmp_0.txt").to_s if $DEBUG and b $stdout.flush end until (i == threads.length) && (not b) puts out if $DEBUG # ------------------------------------------------------