I'm trying to use the script that was suggested here.
My goal is to be able to reuse the script for multiple files. I have one file that contains this script and another one that simply triggers the script multiple times with different parameters.
ReplaceString.bat
@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
:: OldStr [in] - string to be replaced
:: NewStr [in] - string to replace with
:: File [in] - file to be parsed
:$changed 20100115
:$source http://www.dostips.com
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
And let's say:
foo.bat
set oldString=foo
set newString=newFoo
ReplaceString.bat %oldString% %newString% someFile.txt >someFile.txt
ReplaceString.bat %oldString% %newString% someFile2.txt >someFile2.txt
But for whatever reason, the execution stops after successfully running the first call.
I tried to call the ReplaceString.bat
with START
& CALL
, tried not to redirect the output to a file, but each time I ended up having the same result.
I would like to be able either forcing foo.bat
to continue to run, or ReplaceString.bat
not to exit.
Edit:
I mistakenly assumed the script was ending prematurely, but what was actually happening is, I just wasn't receiving an output to my console, the commands did run with CALL
command.
The other problem with my script was redirecting the output back to the input file, which was fixed by redirecting output to a temporary file and replacing it with the original once the call ended.