-2

I'm using a bat script that writes code for a bat script to a text file and was wondering if there was a way to mass escape the code and treat it as text?

At the moment I'm using the below but it's not escaping the code

@echo off
(
echo code
echo code
)>"text.txt"
squidg
  • 327
  • 3
  • 9
  • 23
  • Could you have a look at https://stackoverflow.com/questions/1015163/heredoc-for-windows-batch ? It's about the emulation of heredoc in windows batch, maybe that approach works for you? – fvu May 28 '18 at 13:20

1 Answers1

1
@echo off
for /f "delims=[]" %%n in ('find /n "REM DATA:" "%~dpnx0"') do set /a n=%%n
more +%n%  "%~dpnx0">myNew.bat
REM rest or your batchfile
goto :eof
REM DATA:
@echo off
echo this is your new batchfile
echo on computer %computername%
REM etc.

the for just gets the line number where your new content is stored (start of DATA section), the more command writes that content to a new file (in fact "the currently running batchfile, skipping the first n lines").

The code after REM DATA: isn't processed by the parser (just copied by more), so no escaping needed.

Note: more converts TABs to (several) spaces.

Stephan
  • 53,940
  • 10
  • 58
  • 91