在 powershell 命令中使用空格運行程序我在加載包含空格的字符串時遇到錯誤,並且需要在雙引號之間傳遞。
Names Default to Here(1);
parameter_A = "this has spaces";
parameter_B = "specific.domain.com";
command = "program -Name \!"" || parameter_A ||"\!" -Path \!"" || parameter_B || "\!"";
write(command );
// outputs the expected:
// program -Name "this has spaces" -Path "specific.domain.com"<BR />
add_result = RunProgram(
Executable( "powershell.exe" ),
Options( {"/c", command } ),
ReadFunction( "text" ));這參數_A中斷執行,因為它認為傳遞了更多參數。 然而,如果我在 powershell 中復制並粘貼 write 的輸出,該命令就可以工作。
我缺少什麼?
高級統計建模消費者和市場研究數據混合和清理回复:在 powershell 命令中使用空格運行程序這裡全面解釋了為什麼 Windows 命令行如此難用。 引號並沒有真正起到我們認為的作用。
我會像您一樣混合使用撇號和引號,因為這樣更容易理解。
回复:在 powershell 命令中使用空格運行程序這對我之前類似的案例有幫助:將報價傳遞到運行程序應用程序
escapedquote = "\!\\!"";
回复:在 powershell 命令中使用空格運行程序Names Default to Here(1);
parameter_A = "this has spaces";
parameter_B = "specific.domain.com";
command = "powershell "\!"program -Name '" || parameter_A ||"' -Path '" || parameter_B || '"\!"";
write(command );
// outputs the expected:
// powershell "program -Name 'this has spaces' -Path 'specific.domain.com'"
add_result = RunProgram(
Executable( "cmd.exe" ),
Options( {"/C", command } ),
ReadFunction( "text" ));這對我有用,不確定是否有更好的不使用單引號的解決方案。