Here an example of how I shell to external apps, should also work with Powershell. Copy the working command from your console between the {} without extra delimiters. The %Q also makes it possible to do interpolation of variables in case your command is not always the same, it works the same way as between the " delimiter.
All the output is captured by the " 2>&1" and enumerated line by line in the block after while.
In case more than one line is captured you need to check which line the result you are after is displayed and return the result.
def powershell
command = %Q{your command just like you execute it in a console}
IO.popen(command+" 2>&1") do |pipe|
pipe.sync = true
while lijn = pipe.gets
# do whatever you need with the output of the command
# return the result
end
end
end
Use the %q{} alternative if you don't need the interpolation since that also could give problems. Use the Ruby comamnd in the same console as where you get your powershell results. Ensure you can run powershell from there (must be in the path).
But as I understand this will get you the name and version of the installed products on your pc.
Why not use just Ruby ? It's way more faster than the VERY slow Wmi queries.
require 'win32/registry'
Win32::Registry::HKEY_LOCAL_MACHINE.open(
'Software\Microsoft\Windows\CurrentVersion\Uninstall'
) do |reg|
reg.each_key do |key|
k = reg.open(key)
puts key
puts k["DisplayName"] rescue "?"
puts k["DisplayVersion"] rescue "?"
puts
end
end