user2187308
user2187308

Reputation: 67

Batch script closing parenthesis issue

I have the following batch script to replace the supplied text with some other text.

@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

Now, I am trying to automate the build and set up of my application. I invoke the above script from following batch.

@echo off

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

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

Due to the ')' in the path, I get the following in the console.

\Apache was unexpected at this time.

Please help me to escape the ')'.

Upvotes: 0

Views: 96

Answers (1)

foxidrive
foxidrive

Reputation: 41234

This is one problem: change "%3" to "%~3"

It is why the characters in the path string are not protected, because %3 is already double quoted.

Upvotes: 1

Related Questions