我正试图从Ruby中找出如何做到这一点,这样我就可以将它作为一个事实在Puppet中使用:
PS C:\> (& "$env:ProgramFiles\EMC NetWorker\nsr\bin\nsrports.exe" | Select-String -Pattern Service | Select-Oject -ExpandProperty line).split(" ")[2]
7937-9936我厌倦了下面的内容,但我意识到PowerShell不是解决方案。使用irb,我得到了以下内容:
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我修改后的问题是:我如何才能从变量中得到7937-9936部分?
编辑:如果从我对这个的第一次拍摄开始,下面是什么
原始标题: Ruby + powershell:如何摆脱命令路径中的空格?
我尝试过的每一件事要么抱怨'EMC NetWorker‘中的空间问题,要么根本不返回任何东西。我假设我需要做一些这样的事情,但不确定是什么:
exec "powershell -noprofile (& "$env:ProgramFiles\EMC NetWorker\nsr\bin\nsrports.exe" | Select-String -Pattern Service | Select-Object -ExpandProperty line).split(" ")[2]命令的输出应该如下:
7937-9936任何帮助都将不胜感激!
发布于 2015-04-19 18:21:57
你可以试试这个:
a.match(/Service ports: ([0-9]+-[0-9]+)/)[1]
https://stackoverflow.com/questions/29733856
复制相似问题