I'm trying to figure out how to do this from Ruby so that I can use it as a fact in Puppet:
PS C:\> (& "$env:ProgramFiles\EMC NetWorker\nsr\bin\nsrports.exe" | Select-String -Pattern Service | Select-Oject -ExpandProperty line).split(" ")[2]
7937-9936
I tired what's below to no avail but realized that PowerShell isn't the solution. Using irb
I got this:
irb(main):003:0> a = `'C:/Program Files/EMC NetWorker/nsr/bin/nsrports.exe'`
=> "Service ports: 7937-9936 \nConnection ports: 0-0 \n"
irb(main):005:0> puts a
Service ports: 7937-9936
Connection ports: 0-0
=> nil
My revised question is this: how can I get just the 7937-9936
part from the variable?
EDIT: What's below if from my first take on this
Original title: Ruby exec + powershell: how do I escape a space in the command's path?
Everything I have tried either complains about the space in 'EMC NetWorker' or doesn't return anything at all. I am assuming I need to do some form of this but not sure what:
exec "powershell -noprofile (& "$env:ProgramFiles\EMC NetWorker\nsr\bin\nsrports.exe" | Select-String -Pattern Service | Select-Object -ExpandProperty line).split(" ")[2]
The output from the command should be this:
7937-9936
Any help would be appreciated!
You can try this:
a.match(/Service ports: ([0-9]+-[0-9]+)/)[1]