【发布时间】:2015-04-20 08:51:43
【问题描述】:
我正在尝试从 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
任何帮助将不胜感激!
【问题讨论】:
标签: ruby powershell puppet facter