Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows批处理中使用PowerShell命令和倒勾换行符_Windows_Powershell_Escaping - Fatal编程技术网

在Windows批处理中使用PowerShell命令和倒勾换行符

在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

我正在尝试编写一个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.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!"