[英]Calling PowerShell from a batch file fails
当我从命令行调用以下命令时,一切正常。 但是,当我将其放在.bat文件中并调用该文件时,出现语法错误,提示我在命令末尾缺少结尾'。
powershell -command "& 'C:\Program Files\TortoiseSVN\bin\svn.exe' status | ? { $_ -Match '^!\s+(.*)' } | % { & 'C:\Program Files\TortoiseSVN\bin\svn.exe' rm $Matches[1] }"
当我从.bat调用它时,发生的一件奇怪的事情是该命令被神秘地更改了。 这是.bat文件的输出:
C:\workspace>powershell -command "& 'C:\Program Files\TortoiseSVN\bin\svn.exe' status | ? { $
_ -Match '^!\s+(.*)' } | \Program Files\TortoiseSVN\bin\svn.exe' rm $Matches[1] }"
The string is missing the terminator: '.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
我100%确保.bat文件的内容和我手动运行的命令相同,并且编辑器(Notepad ++)不会执行像将命令分成两行那样的愚蠢事情。
我究竟做错了什么?
字符串中任意位置的字符%
必须在批处理文件中再加上%
进行转义,才能解释为文字字符。
powershell -command "& 'C:\Program Files\TortoiseSVN\bin\svn.exe' status | ? { $_ -Match '^!\s+(.*)' } | %% { & 'C:\Program Files\TortoiseSVN\bin\svn.exe' rm $Matches[1] }"
在批处理文件中工作。 在命令提示符窗口中输入for /?
或for /?
help for
for /?
您可以阅读有关在第一个帮助页面输出中转义%
要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.