在Windows批处理中使用PowerShell命令和倒勾换行符
我正在尝试编写一个Windows批处理文件,该文件将替换尖括号(>查看powershell.exe命令行选项。您可以使用脚本块:在Windows批处理中使用PowerShell命令和倒勾换行符,windows,powershell,escaping,Windows,Powershell,Escaping,我正在尝试编写一个Windows批处理文件,该文件将替换尖括号(>查看powershell.exe命令行选项。您可以使用脚本块: powershell -command {(gc input.txt) -replace "><", ">`n<" | sc output.txt} powershell-command{(gc input.txt)-replace“>`n避免使用转义字符和双引号 powershell -command "(gc d:\t\input.tx
powershell -command {(gc input.txt) -replace "><", ">`n<" | sc output.txt}
powershell-command{(gc input.txt)-replace“>`n避免使用转义字符和双引号
powershell -command "(gc d:\t\input.txt) -replace '><', ('>'+[char]10+'<') | sc d:\t\output.txt"
powershell-command”(gcd:\t\input.txt)-replace'>'+[char]10+'我已经解决了这个问题。
我还使用了延迟扩展,因此最后的命令是:
powershell -Command "(gc !inputfile!) -replace (\"^>^<\", \"^>`n^<\") | sc !outputfile!"
powershell-Command“(gc!inputfile!)-替换(\”^>^`n^如果您已经在PowerShell中,则只能使用scriptblock参数;命令提示解释器不知道什么是PowerShell scriptblock,这在批处理文件中不起作用,并尝试运行sc.exe
来管理服务。引用问题的通用修复方法是-encodeCommand
参数,d在这里描述
powershell -command {(gc input.txt) -replace "><", ">`n<" | sc output.txt}
powershell -command "(gc d:\t\input.txt) -replace '><', ('>'+[char]10+'<') | sc d:\t\output.txt"
powershell -Command "(gc !inputfile!) -replace (\"^>^<\", \"^>`n^<\") | sc !outputfile!"