2014-07-15 100 views
0

我有以下批处理脚本来替换提供的文本和一些其他文本。批处理脚本右括号问题

@echo off 
setlocal 


call :FindReplace %1 %2 %3 

exit /b 

:FindReplace <findstr> <replstr> <file> 
set tmp="%temp%\tmp.txt" 
If not exist %temp%\_.vbs call :MakeReplace 
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
    for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
    echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa 
    <%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp% 
    if exist %tmp% move /Y %tmp% "%%~dpnxa">nul 
) 
) 
del %temp%\_.vbs 
exit /b 

:MakeReplace 
>%temp%\_.vbs echo with Wscript 
>>%temp%\_.vbs echo set args=.arguments 
>>%temp%\_.vbs echo .StdOut.Write _ 
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1) 
>>%temp%\_.vbs echo end with 

现在,我正试图自动化构建和设置我的应用程序。我从下一批调用上述脚本。

@echo off 

set a=C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf 

call Text_Replacer "branch-1" "branch-2" "%a%" 

由于路径中的')',我在控制台中得到以下内容。

\Apache was unexpected at this time. 

请帮我摆脱''''。

+0

使用powershell。 – Ben

回答

1

这是一个问题:改变"%3""%~3"

这就是为什么在路径字符串中的字符都得不到保障,因为3%已经是双引号括起来。

+0

嘿,谢谢......那很好用...... – user2187308