Ruby with WMI but that is not the problem

Hey I am new to ruby and I do Windows administration. I have been
playing with wmi and ruby, having a problem. This is not a problem
with th wmi part but when I use get. I am asking for a computer name
and then putting that information into the script. This does not work

[Start Code]
require 'win32ole'

puts "what is the computer name that you want to use??? "
cpuName = gets
cpuName.chomp

mgmt = WIN32OLE.connect("winmgmts:\\\\#{cpuName}")
mgmt.InstancesOf("Win32_ComputerSystem") .each{ |item| puts item.name +
"\n" + item.Manufacturer + " - " + item.Model}
mgmt.InstancesOf("Win32_SystemEnclosure").each{ |dev| puts
dev.SerialNumber}

[/End Code]

This does

[Start Code]

require 'win32ole'

cpuName = 'aname'

mgmt = WIN32OLE.connect("winmgmts:\\\\#{cpuName}")
mgmt.InstancesOf("Win32_ComputerSystem") .each{ |item| puts item.name +
"\n" + item.Manufacturer + " - " + item.Model}
mgmt.InstancesOf("Win32_SystemEnclosure").each{ |dev| puts
dev.SerialNumber}

[/End Code]

Can someone shed some light on this???

You need to do either:
  cpuName = cpuName.chomp
or
  cpuName.chomp!

Regards,

Sean

ยทยทยท

On 11/8/05, happy-jack <timgerr@gmail.com> wrote:

cpuName.chomp

happy-jack wrote:

Hey I am new to ruby and I do Windows administration. I have been
playing with wmi and ruby, having a problem. This is not a problem
with th wmi part but when I use get. I am asking for a computer name
and then putting that information into the script. This does not work

[Start Code]
require 'win32ole'

puts "what is the computer name that you want to use??? "
cpuName = gets

Try STDIN.gets

cpuName.chomp

Try cpuName.chomp!

mgmt = WIN32OLE.connect("winmgmts:\\\\#{cpuName}")
mgmt.InstancesOf("Win32_ComputerSystem") .each{ |item| puts item.name +
"\n" + item.Manufacturer + " - " + item.Model}
mgmt.InstancesOf("Win32_SystemEnclosure").each{ |dev| puts
dev.SerialNumber}

[/End Code]

Regards,

Dan

Thank you, I learned somthing new.