【发布时间】:2015-10-13 01:48:26
【问题描述】:
我正在尝试使用从 Windows 7 中的 bat 文件运行的 PowerShell 命令将文件 (temp1.txt) 中的所有双引号替换为两个双引号:
powershell -Command "(gc c:\temp\temp1.txt) -replace '\"', '\"\"' | Out-File -encoding UTF8 c:\temp\temp2.txt"
我不断收到错误:
'Out-File' is not recognized as an internal or external command.
当我更改命令以将字母“a”替换为字母“b”时,它可以正常工作,如下所示:
powershell -Command "(gc c:\temp\temp1.txt) -replace 'a', 'b' | Out-File -encoding UTF8 c:\temp\temp2.txt"
我需要转义双引号,因为整个 powershell -Command 都在双引号字符串中。你如何逃避双引号?
【问题讨论】:
标签: powershell batch-file escaping