0

我正在尝试从命令行运行 powershell 脚本以及参数,但它总是失败并出现以下错误。任何人都可以帮忙吗?

cmd /c "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /"<?xml version=/'1.0/'?><Settings><Keys>243</Keys></Settings>/""

错误:

< was unexpected at this time
4

1 回答 1

0

用反引号转义中间的双引号。

cmd /c "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /`"<?xml version=/'1.0/'?><Settings><Keys>243</Keys></Settings>/`""

编辑:为了解释,它将您的原始命令读取为:

使用以下命令启动命令提示符:

cmd /c "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /"

然后将以下内容作为该命令的参数或输入导入:

<?xml version=/'1.0/'?><Settings><Keys>243</Keys></Settings>/""

嗯,你是对的,它在 < 这是一个保留字符上出错,我打赌它也会在 > 上出错。逃避那些,它应该工作。

cmd /c 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /"`<?xml version=/''1.0/''?`>`<Settings`>`<Keys`>243`</Keys`>`</Settings`>/"'

测试它在我的机器上工作,没有给出错误。

于 2014-07-31T16:43:28.353 回答