From: Park Heesob Date: 2002-08-20T23:50:14+09:00 Subject: Re: thread control Hi, "Shashank Date" wrote in message news:oqr89.15682$Hf.526056@twister.kc.rr.com... > Hi Park, > .... > > That does seem to make a difference ... the main program does end as I > expected it to. > > But what if I want to collect the partial output of my threads (in this case > "ping" commands) say in a file or something. > The array out[] that I have used does not seem to get it. > > And the ping processes are still running .. how do I get rid of them. > > (I realize that this is a different issue now ;-)). > > Thanks for the suggestion, though. > > -- Shanko > How about this modified version? # ------------------------------------------------------ cmds = [ "ping 10.0.0.0 -n 30 -w 1000 ", "ping 10.0.0.0 -n 60 -w 1000 ", "ping 10.0.0.0 -n 90 -w 1000 " ] out = [] threads = [] for c in cmds threads << Thread.new(c) { |myCmd| puts "#{myCmd}" f = IO.popen(myCmd) Thread.current["f"] = f while not f.eof? out << f.gets end } 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) threads.each { |t| if t.alive? t["f"].close t.exit end } puts out if $DEBUG # ------------------------------------------------------ Park Heesob