I use the below batch script which has binary part (.exe program) append to the bottom of the script. I used this trick to attach binary part to my batch script:
::Append binary part to your batch file with COPY
copy /y /a "batchscript.bat" + /b program.exe /b combined.bat
In order to extract the binary part from the batch script (combined.bat), I use the following method with "findstr" command:
;;;===,,, @ECHO OFF
;;;===,,, SETLOCAL ENABLEEXTENSIONS
;;;===,,,
;;;===,,, echo test line1
;;;===,,, echo test line2
;;;===,,,
;;;===,,, findstr /v "^;;;===,,," %~f0 > program.exe
;;;===,,,
;;;===,,, echo test line3
;;;===,,, echo test line4
;;;===,,, exit /b
;;;===,,, ::Below are binary data for program.exe
binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
...
So this piece of code extracts the binary part from the script to program.exe:
findstr /v "^;;;===,,," %~f0 > program.exe
But as a down-side, each line of the script part must begin with following prefix
;;;===,,,
What I want to do is to use the prefix ";;;===,,," only at the last line of code and extract all binary data after this line. Is it possible to achieve this via some crazy combination of findstr + for loop + if command? Example:
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
echo test line1
echo test line2
HERE IS THE CODE TO EXTRACT BINARY PART AFTER LAST SCRIPT LINE
echo test line3
echo test line4
exit /b
;;;===,,, ::Below are binary data for program.exe
binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
binarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinarybinary
...
Many thanks in advance.