Noodlebear
Noodlebear

Reputation: 27

Batch file that creates a new batch

I need to create a batch file with code written in it from a batch file, so I tried this code:

Echo @echo off echo Hello pause > NewBatch.bat

But NewBatch.bat has all of those lines written in one single line. I kind of expected this this to happen, but is there any way I can make it write individual lines?

Upvotes: 0

Views: 48

Answers (3)

Monacraft
Monacraft

Reputation: 6630

Easy:

set /p n=^


Rem Above 2 lines are needed
Echo @echo off%n%echo Hello%n%pause > NewBatch.bat

And to ever produce a new line simply use %n%.

Mona.

Upvotes: 1

foxidrive
foxidrive

Reputation: 41234

If you really want it in one line then this is an option:

(Echo.@echo off&echo.echo Hello&echo.pause)>NewBatch.bat

and a convoluted option:

>NewBatch.bat Echo.@echo off&>>NewBatch.bat echo.echo Hello&>>NewBatch.bat echo.pause 

Upvotes: 0

MC ND
MC ND

Reputation: 70923

(   echo @echo off
    echo echo hello
    echo pause
) > NewBatch.bat

Upvotes: 2

Related Questions