我试图弄清楚如何从 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 exec + 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
任何帮助,将不胜感激!