Author Options:

Creating batchfile with batchfile Answered

Hi. I wanna make a batchfile that creates another batchfile with text. I've tried to use the echo command like this: "echo echo off > something.bat" and that do work but I need to use it like this:" echo ( echo off color a cls echo welcome etc. ) > something.bat somebody help! thanks in advance.


Is this what you are looking for?

@echo off
echo @echo off > "something.bat"
echo color a >> "something.bat"
echo cls >> "something.bat"
echo echo Welcome >> "something.bat"

Or try this one:

@echo off
color 0e
echo What do you want the title to be?
set /p title=
set /a line=1
echo What do you want line #1 to say?
set /p command=
echo %command% > "%title%.bat"
set /a line=%line +1
echo What do you want line #%line% to say?
set /p command2=
echo %command2% >> "%title%.bat"
goto two

What you want to use is called a "Here document", but I'm almost 100% certain that dos/win batchfiles doesn't support that. What's wrong with using the standard output redirects? echo echo off > something.bat echo color a >> something.bat echo cls >> something.bat echo echo welcome >> something.bat

I need to put more than that in the file. When I compile my .bat files to .exe files, I can only include 1 file and I need to include 2, 1 .exe file and 1 .rar file so I have to create one of them using the echo method but it doesn't work, so.

echo doesn't do anything. and you can't really make a batch file that creates another batch file, unless you make something like a polymorphic virus

I think I lost you when you said that you want to include a exe and a rar-file in the batchfile... There's something that I don't understand here. If we focus on the expected outcome instead of a problem with a proposed solution it might be clearer to me. (I've used dos since 1982, version 1.25, so I've done most stuff that's possible with it during all these years....) So you have a bat-to-exe -compiler, and then you have three files that you want to integrate into one new exe-file? A batchfile, a rar-archive and a (premade) exe-file. Right? I must admit that I've never used a bat-to-exe compiler. If I want an exefile I use a real language for that, or back in the old days used Debug and created a com-file (a com-file is kind of a small lightweight exe-file) on the fly. What bat-to-exe -compiler are you using?

Yes I know what a .com file is I'm quite a pro with the ms-dos language, and I think I know very much more than u think. Download this file: http://www.download.com/3000-2069_4-10715331.html
Try it out and you'll see what I meen with including. The .exe that is created will create a file if included and that's very usable, but I need to include 2 files.

I didn't assume anything about your proficiency level, I just took a middle ground to be on the safe side. Anyhow... Why not just put both the exe and the rar-file into a sfx (self extracting archive) , 7-zip is a nice fee one, and include that file in the bat-to-exe-converter. Then as the first step in the batchfile run the sxf to generate both files. and then continue as usual. But you probably need to remove both files "manually" in the end of the batch since it is only cleaning up its own files after the run. I might still be missing something with how you actually want to use this....

Sure but the user still has to click "INSTALL" so.

Yes, you need a silent sfx extractor. This can be faked this way with 7-zip: @echo off echo Hello world! Now unpacking files start test.exe -y /Q echo Done. Press any key to end this batchfile pause The test.exe is the sfx with some files in it. I took the batchfile (above) and the test.exe-file and created an exe with the converter. And then ran the resulting file. It worked more or less perfectly. The only problem was that a small window was shown on the screen for like 0.1 seconds. I'm sure that there are some other sfx-creators that allows for completely silent and invisible extractions.

Nope doesn't work for me. Using winrar

Learn to use your tools. :-) There's some perfect options in winrar to handle this. In the General-tab check the "Create SFX archive" checkbox. In the Advanced-tab click on the SFX-options button. In the Mode-tab there you select "Hide all" and "Overwrite all files" That's it. You now have a SFX that extracts all files completely silent and invisible. My batchfile now looks like this when using a winrar-sfx: @echo off echo Hello world! echo Now unpacking files test.exe echo Done. Press any key to end this batchfile pause

Yeah that's great thanks very much, but It still whould be better to include 2 files when compiling though.


10 years ago

Any other command to use???

Just type "copy con name.bat". Then you are editing a file called "name.bat".

No, it doesn't work for this


Reply 10 years ago

It can be mighty powerful if it invokes a basic program. something like QBASIC MAKEBAT /RUN i think, but first you have to write basic (with edit or qbasic) like: OPEN "NEWBAT.BAT" FOR OUTPUT AS #1 PRINT #1,"ECHO WHATEVER" PRINT #1,"NEWBAT":REM UH OH, THIS BAT IS RECURSIVE CLOSE #1:END:REM JUST MADE A BAT FILE alt save as "MAKEBAT.BAS" and edit "MAKEBAT.BAT" to evoke it. It's been a while so there are probably little errors above. (OUTPUT maybe should be RANDOM or BINARY instead? alt-h helps.) And also, not everyone has qbasic in cmd path so if you're trying to write some kind of virus most people will be immune.