2013-02-05 254 views
2

執行PowerShell中運行ps命令提示符罰款:從紅寶石

Get-WmiObject Win32_Share -computer "Server" -filter "Name = 'ShareName'" 

當加入到Ruby我能得到這個執行(因爲它不需要引號):

powershell (Get-WmiObject Win32_Share -computer "Server") 

但不包含篩選參數(需要引號):

powershell (Get-WmiObject Win32_Share -computer "Server" **-filter "Name = 'ShareName'"**) 

錯誤的輸出不顯示雙引號。我嘗試了我知道的一切來逃避他們,沒有任何工作。

試圖(... -filter \"Name = 'ShareName'\")
試圖%x{}代替``
試圖單引號

+0

我不認爲我在這裏看到任何有效的Ruby代碼。你可以發佈你的實際ruby代碼,告訴我們你期望它做什麼,而不是它實際上做什麼? –

+0

它從Ruby(耙,rake)腳本執行。我將Ruby包含在標籤中,因爲它或PowerShell似乎與引號混淆,或者很可能我沒有找到使其正確工作的正確引號序列。所以,Ruby是包含PS命令的''和%x []。 – Dean8088

回答

0

在的powershell,一個雙引號串之間的值被解釋,如含有字符串「Hello World」的對象$HelloWorld。 Powershell以與處理"$helloWorld"相同的方式處理$HelloWorld。但是,如果您鍵入'$HelloWorld',它將逐字解釋並將對象名稱$ HelloWorld打印爲字符串。

PS> $HelloWorld = "Hello World" 
PS> $helloworld 
Hello World 
PS> "$helloworld" 
Hello World 
PS> '$helloworld' 
$helloworld 

嘗試這樣的事情......

PS> "'$helloworld'" 
'Hello World'