0

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!

GeneBean
  • 361
  • 4
  • 17

1 Answers1

0

You can try this:

a.match(/Service ports: ([0-9]+-[0-9]+)/)[1]

dx7
  • 804
  • 5
  • 11
  • After trying your suggestion I didn't have any luck but it did help me realize I was over complicating things. I have updated my question accordingly. Thanks! – GeneBean Apr 20 '15 at 00:11
  • Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others. (This post was flagged by at least one user, presumably because they thought an answer without explanation should be deleted.) – Nathan Tuggy Apr 20 '15 at 01:19
  • I think this solution is very simple and self explanatory. – dx7 Apr 20 '15 at 01:23
  • FWIW, I found this to be a clear, concise answer that solved my issue. – GeneBean Apr 20 '15 at 12:00