我需要在不使用双引号"
的情况下从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
我不能使用双引号的原因是因为我正在使用vboxmanage
中的post-install-command=
参数,该参数已经使用了双引号。
1条答案
按热度按时间jtoj6r0c1#
Start-BitsTransfer
开头的内容包括在(转义的)"..."
中**,即,将单双引号字符串传递给powershell.exe
的(位置隐含的)-Command
参数,这将阻止cmd.exe
解释字符串的内容(潜在的cmd.exe
环境变量引用除外,例如%OS%
)。"..."
,就像您的情况一样,"..."
字符串外部的&
将被解释为cmd.exe
元字符(语句分隔符),并且调用Break*('...'
字符串只被PowerShell识别,而不被cmd.exe
识别)。^
转义,但将整个-Command
参数包含在"..."
中是更简单的解决方案。(此外,尽管这在实践中很少出现问题,但在没有"..."
封闭的情况下会发生空格标准化,即在每次运行时将多个空格合并为一个空格)。powershell.exe
命令本身嵌入在作为vboxmanage
选项的一部分传递给vboxmanage
的"..."
字符串中,因此您必须*转义"
字符。是powershell.exe
调用的一部分,即as\"
。因此,在
vboxmanage
调用的上下文中,使用如下内容-注意外部的"..."
和嵌入的内部\"...\"
: