title: Batch file creating another batch file, how to ignore commands when writing lines?
body: <p>having a bit of trouble with a windows batch file I'm writing.</p>
  
  <p>I need the batch file to write some particular lines to another batch file, the method I have been using is:</p>
  
  <pre><code>type NUL &gt; batchfile.bat
  ECHO texttobewrittentofile &gt;&gt; batchfile.bat
  ECHO texttobewrittentofile &gt;&gt; batchfile.bat
  ECHO texttobewrittentofile &gt;&gt; batchfile.bat
  ...
  etc
  </code></pre>
  
  <p>Most of the lines write fine, there are a few different problems I'm having with my batch file writing to another batch file though.</p>
  
  <p>The code for my batch file to write to another batch file is:</p>
  
  <pre><code>ECHO @echo off &gt;&gt; GenerateEmail.bat
  ECHO ECHO Opening Stunnel &gt;&gt; GenerateEmail.bat
  ECHO pushd .\stunnel\ &gt;&gt; GenerateEmail.bat
  ECHO start "" stunnel.exe stunnel.conf &gt;&gt; GenerateEmail.bat
  ECHO popd &gt;&gt; GenerateEmail.bat
  ECHO ECHO Determining latest log for use with blat &gt;&gt; GenerateEmail.bat
  ECHO pushd O:\Logs\%clientname%\ &gt;&gt; GenerateEmail.bat
  ECHO for /f "tokens=*" %%a in ('dir /b /od') do set newest=%%a &gt;&gt; GenerateEmail.bat
  ECHO popd &gt;&gt; GenerateEmail.bat
  ECHO ECHO Generating email containing contents of latest log &gt;&gt; GenerateEmail.bat
  ECHO pushd .\blat307\full\ &gt;&gt; GenerateEmail.bat
  ECHO ECHO Y | xcopy "O:\Logs\%clientname%\%newest%" ".\" &gt;&gt; GenerateEmail.bat
  ECHO blat.exe "%newest%" -to %clientemail% -cc %gmailemail% -server 127.0.0.1:1099 -subject "Offsite Backup for "%1" "%2" - %clientname%" -sig sig.txt &gt;&gt; GenerateEmail.bat
  ECHO DEL .\*.log &gt;&gt; GenerateEmail.bat
  ECHO popd &gt;&gt; GenerateEmail.bat
  ECHO ECHO Closing Stunnel &gt;&gt; GenerateEmail.bat
  ECHO pushd .\stunnel\ &gt;&gt; GenerateEmail.bat
  ECHO stunnel.exe -exit &gt;&gt; GenerateEmail.bat
  ECHO popd &gt;&gt; GenerateEmail.bat
  </code></pre>
  
  <p>I'm not getting the desired output that I would like, I'm having issues with:</p>
  
  <p><code>ECHO Y | xcopy "O:\Logs\%clientname%\%newest%" ".\" >> GenerateEmail.bat</code></p>
  
  <p>coming out as</p>
  
  <p><code>0 File(s) copied</code></p>
  
  <p>and everywhere that I need %% it comes out as %, as well as the line starting with "blat.exe" isn't written at all amongst other problems. Is there any way to get a batch file to write lines of text without acknowledging any commands or symbols contained in those lines?</p>
  
  <p>Kane.</p>