1
我尝试在批处理文件中调用PowerShell命令:PowerShell的命令,其中双引号是必需的命令里面
powershell -Command "(gc test.txt) -replace ("~\[","`r`n[") | sc test.txt"
但总是失败,此错误
At line:1 char:29
+ (gc test.txt) -replace (~\[,`r`n[) | sc test.txt
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : MissingArgument
我尝试用单引号替换字符串
powershell -Command "(gc test.txt) -replace ('~\[','`r`n[') | sc test.txt"
但反引号转义字符被对待像任何其他文本字符出现在用单引号括起来的字符串中时。
单引号,甚至没有必要的,逃逸的双引号是足够的。 –
它给出了“错误:无法识别的命令” –
@GeraldSchneider如果我不把命令放在单引号中,我会得到一个错误 - 是吗? –