"〈“运算符保留供将来使用(命令行中的PowerShell脚本)

vuktfyat  于 2023-02-16  发布在  Shell
关注(0)|答案(1)|浏览(216)

我尝试从命令行运行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
4sup72z8

4sup72z81#

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

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

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

相关问题