On 07.09.2009 18:58, geo ssscripting wrote:
> Here's the rewrite using IO.popen:
> 
> threads = []
> 
> (1..254).each do |i|
>   puts "pinging #{i}"
>   threads << Thread.new {
>     content = ""
>     IO.popen("ping 192.168.0.#{i}") do |io|
>       io.each { |l| content << l }
>     end
>     content
>   }
> end
> 
> threads.each do |t|
>   t.join

#join is superfluous when using #value.

>   puts t.value
> end
> 
> This doesn't behave different. My Ruby -v outputs this :

What exactly do you mean?  What do you expect?  If you refer to seeing 
the output of both ping commands sequentially: with the code you 
presented you always will get your output sequentially simply because 
you wait until all threads finish and then you'll iterate them and print 
the output of one thread at a time.  Your ping commands will run in 
parallel.

> ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
> 
> I'm running Windows XP.

	robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/