title: Replace String with Batch for multiple files
body: <p>I'm trying to use the script that was suggested <a href="https://stackoverflow.com/a/20339408/3501205">here</a>.</p>
  
  <p>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.</p>
  
  <p><strong>ReplaceString.bat</strong></p>
  
  <pre><code>@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"&amp;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.
  )
  </code></pre>
  
  <p>And let's say:</p>
  
  <p><strong>foo.bat</strong></p>
  
  <pre><code>set oldString=foo
  set newString=newFoo
  
  ReplaceString.bat %oldString% %newString% someFile.txt &gt;someFile.txt
  
  ReplaceString.bat %oldString% %newString% someFile2.txt &gt;someFile2.txt
  </code></pre>
  
  <p>But for whatever reason, the execution stops after successfully running the first call.</p>
  
  <p>I tried to call the <code>ReplaceString.bat</code> with <code>START</code> &amp; <code>CALL</code>, tried not to redirect the output to a file, but each time I ended up having the same result.</p>
  
  <p>I would like to be able either forcing <code>foo.bat</code> to continue to run, or <code>ReplaceString.bat</code> not to exit.</p>
  
  <p><strong>Edit:</strong>
  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 <code>CALL</code> 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. </p>