Ben
Ben

Reputation: 777

Create new batch file from batch file

Is it possible to create a new batch file from an existing? For example in Java, C++ pretty much any other language I can run one .exe and create a different .exe with separate code. Is this possible to do in batch files?

Let's say I want test.bat to be this

echo hello hello

and I want it to create another .bat file called test2.bat which will contain this:

echo hi hi

Upvotes: 2

Views: 1565

Answers (1)

manlio
manlio

Reputation: 18902

You can use echo and redirect the output to a batch file:

  • test.bat

    @echo off
    @echo hello hello
    @echo echo hi hi > test2.bat
    @echo echo append something >> test2.bat
    

One > to create/overwrite any file that already exists; two > characters to append to the file.

Upvotes: 1

Related Questions