Creating a batch file with multiple lines using a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
david.carver
Posts: 2
Joined: 05 Feb 2012 02:47

Creating a batch file with multiple lines using a batch file

#1 Post by david.carver » 05 Feb 2012 02:55

I need to be able to use a batch file to create another batch file with multiple lines of code. i have used the
cd C:\Documents and Settings
echo set /a var1=12 >newfile.bat

this gives me a new .bat file called newfile.bat with "set /a var1=12" inside but i need to define more than one variable in my newfile.bat.

How do i do this?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Creating a batch file with multiple lines using a batch

#2 Post by Ed Dyreen » 05 Feb 2012 03:09

'
[edit] forgot to escape ^!

Code: Select all

@echo off

>newfile.bat (
   echo.set /a var1=12
   echo.set /a var1=12
   echo.set /a var1=12
   echo.set /a var1=12
)
>>newfile.bat echo.append

type newfile.bat
pause

Code: Select all

@echo off &setlocal enableDelayedExpansion

>newfile.bat (
   echo.!"!<&&||> special characters must be quoted ^! <&&||>!"!
   echo.!"!<&&||> special characters must be quoted ^! <&&||>!"!
   echo.!"!<&&||> special characters must be quoted ^! <&&||>!"!
   echo.!"!<&&||> special characters must be quoted ^! <&&||>!"!
)
type newfile.bat
pause

david.carver
Posts: 2
Joined: 05 Feb 2012 02:47

Re: Creating a batch file with multiple lines using a batch

#3 Post by david.carver » 05 Feb 2012 14:19

Thanks that worked great!

Post Reply