我需要在不使用雙引號的情況下從 cmd 啟動 powershell 命令"
我當前的命令:
powershell.exe -noexit Start-BitsTransfer -Source 'download link' -Destination 'C:\test.txt'
錯誤:
The string is missing the terminator: '.
CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
我不能使用雙引號的原因是因為我正在使用已經使用雙引號的post-install-command=引數。vboxmanage
uj5u.com熱心網友回復:
最好將所有以
Start-BitsTransferin (escaped)"..."開頭的內容括起來,即將單引號雙引號字串傳遞給 ) 的(位置隱含-Command的)引數powershell.exe,這樣可以防止cmd.exe解釋字串的內容(可能是cmd.exe-format environment-variable參考文獻,例如%OS%)。如果沒有
"...",如在您的情況下,字串&外部將"..."被解釋為cmd.exe元字符(陳述句分隔符),并且呼叫中斷('...'字串僅由 PowerShell 識別,而不是由 PowerShell 識別cmd.exe)。雖然您可以單獨
^-escape 所有 cmd.exe 元字符,但將整個引數包含在其中是更簡單的解決方案。(此外,即使在實踐中很少出現問題,空白規范化也會在沒有封閉的情況下發生,即每次運行多個空格的運行折疊成一個空間)。-Command"...""..."
由于您的整個
powershell.exe命令本身嵌入在"..."作為選項的一部分傳遞給的字串中vboxmanage,因此您必須對字符進行轉義"。作為呼叫的一部分powershell.exe,即as\"。
因此,在您vboxmanage呼叫的背景關系中,使用類似以下的內容 - 請注意外部"..."和嵌入的內部\"...\":
vboxmanage ... post-install-command="powershell.exe -noexit \"Start-BitsTransfer -Source 'download link' -Destination 'C:\test.txt'\""
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/520668.html
標籤:视窗电源外壳命令
上一篇:錯誤:在實體化`<std::iter::Filter<std::iter::Sk...]>::{closure#0}]>::{closure#0}]>`時達到遞回限制
