I wouldn't use a batch... I'd write it in C++, and use temp files that can be created and deleted. Your program would compile as an EXE as you need. If you know C++ or another language, I'd use that language if you are familiar with it to run the processes that you need. In C++ you can use the "SYSTEM" command to pass commands to a command shell like a batch, and the values that you want to pass can run within the C++ program and can be written to a log file as raw ascii etc.
With the batch if your batch is named gg.bat and you are trying to write to it, you might be hitting a file in use problem, where you cant write to the file until it is closed when the batch ends. You can work around this by using a combination of batch files to pass data back and forth and one closes as the other takes control in a back and forth motion, but self containing in a single exe might not be possible.
Which compiler are you using for converting the *.bat to *.exe
Some of the higher end ones have advanced features which cost money, but I dont believe combining batches into a single exe is supported through any of them.
Probably not much help, but figured I'd share this with you...