2014-07-15 190 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