[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Silly issue with if / else with pingecho

ga rg

5/29/2008 3:25:00 PM

I'm positive that this is something incredibly silly. I have a text file
with computer names. I'm assuming that if a computer returns a ping then
it exists. To check this I have the following in a script:

def computer_exists?(computername)
Ping.pingecho(computername)
end

file = File.new(FILENAME, "r")
while (line_item = file.gets)
line_item = line_item.gsub(/\s+$/, $/) #remove trailing white
space

puts "Working on #{line_item}"

if computer_exists?(line_item)
deploy(line_item)
else
puts "Timed out"
end

end
file.close

The file contains three computer items:
ComputerA
ComputerB
ComputerC

When I go to irb and I do Ping.pingecho('ComputerA') it turns it as
true. All three computer exist and are pingable. However, when I run the
above code, ruby outputs Computer A and Computer B as Timed out but
Computer C runs the deploy method.

If I add a ComputerD, then ComputerA,B,C say time out and only Computer
D runs the deploy method.

What have a messed up?

Thank you.
--
Posted via http://www.ruby-....

1 Answer

ga rg

5/29/2008 3:38:00 PM

0

Argh... sorry. I just had to chomp the computername.

Argh!

Thanks for reading.
--
Posted via http://www.ruby-....