'<&#;运算符保留供将来使用(来自命令行的PowerShell脚本)

时间:2014-07-31 16:35:03

标签: powershell command command-line-arguments command-prompt powershell-v1.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

1 个答案:

答案 0 :(得分: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>/""

嗯,你是对的,它在&lt;这是一个保留字符,我打赌它会在&gt;上出错。同样。逃避这些,它应该工作。

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`>/"'

测试在我的机器上工作时没有给出任何错误。

相关问题