Batch File To Make Another Batch File

April 30, 2011 at 10:34:09
Specs: Windows XP, 1gb
OK so i recently finished my best batch file ever. but, i have a problem. to make it more like a program i made a skin to make it look like a program. but i didnt stop there i even made an installer for it. but... i have a problem. i cant find a way for my installer batch to create the other batch file with the code in it. its like making a simple text file but with a few hundred lines text... or in my case i would be making it create 6,834 lines of code... so is there a way to make the batch file create another one?

See More: Batch File To Make Another Batch File

Report •

May 3, 2011 at 08:06:35
You would just need to use the echo command with output redirection:
>testfile.bat echo @echo off
>>testfile.bat echo echo Computer name is %%COMPUTERNAME%%.
>>testfile.bat echo echo Copying files...
>>testfile.bat echo copy file1 file2

There's no reason this wouldn't work with thousands of lines, but it may be a pain to do double percent signs and escape characters (^). The double percents make the variable not be expanded until the second script. Escape characters are required before certain special characters, namely <, >, &.

Report •

May 3, 2011 at 12:29:51
Since it's such a large script it may be easier to use a text marker and place the whole second script at the end of the file(below the marker).

@echo off

rem do whatever, install script.

rem create the new script
for /f "delims=:" %%a in ('findstr /x /n ":otherscriptforoutput" "%~f0" ') do (
   > "newscript.bat" more +%%a "%~f0"

rem be sure to "goto :eof" or "exit /b" before
rem the ":otherscriptforoutput" label
goto :eof

@echo off
echo this is the other script
echo just paste the whole thing below the
echo ":otherscriptforoutput" label
rem ! ^ & % < | > 

Report •

May 3, 2011 at 18:14:23
thanks guys i tried both of your posts and neither worked. when i type the script out (computer would not copy for some reason) and used each of your methods and both gave me an error. first one said "this file already has to many lines and cannot be edited anymore"? what the f**k? anyways the second said it was unable to goto the right label or something??? i dont know. its a pain. i guess i just cant make a realistic program using batch meaning ill have to go back to my old method of using c++ and VB which i had been using for my job as a programmer for years. but i got tired of it so i tried batch and well its not as flexible i guess. funny cause i made a batch file that could restart the computer and run during the boot process before the login screen. which was easy actually but still its a pain that tis not has easy as c++ or VB ya know.

Report •

Related Solutions

May 4, 2011 at 00:01:20
Can you post the exact error?

The sample I provided works for me, so I can't tell what the problem is.

Report •

May 4, 2011 at 09:20:07
i fixed the problem... turns out i had the place i was telling it to save to file to was write protected lol. now i just need to figure out my other problem

Report •

Ask Question