How do I get Ruby 'puts' to write data into a file?

I have the following code that I want to use to ping IP addresses and write to a file. It all works fine, except I can't get it to write to the file.

server = %w'192.168.150.254
192.168.150.251
192.168.120.1
192.168.120.2'

File.open('/test/test2.out','w') do |s|
  server.each do |p|
    r = `ping -a -n 1 #{p}`
    puts r
  end
end
11
задан Andrew Grimm 3 May 2011 в 22:54
поделиться