Problem creating a batch file with a mother-batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mado91
Posts: 15
Joined: 16 Mar 2019 08:03

Problem creating a batch file with a mother-batch file

#1 Post by Mado91 » 17 Mar 2019 12:05

Hi programmers,
I encountered the following problem: I wanted to create a batch file able to create another batch file, here's the code:

Code: Select all

echo @ECHO OFF >> BulBot.bat
echo title BulBot >> BulBot.bat
echo color 70 >> BulBot.bat
echo :masterlabel >> BulBot.bat
echo set /P input= >> BulBot.bat
  
echo IF %input% EQU clear ( >> BulBot.bat
echo CLS >> BulBot.bat
echo ) >> BulBot.bat
  
echo IF %input% EQU readme ( >> BulBot.bat
echo start C:\BulBot\readme.txt >> BulBot.bat
echo ) >> BulBot.bat
  
echo goto masterlabel >> BulBot.bat
Everything went ok until I realised that the output batch code was the following:

Code: Select all

@ECHO OFF 
title BulBot 
color 70 
:masterlabel 
set /P input= 
IF  EQU clear ( 
CLS 
) 
IF  EQU readme ( 
start C:\BulBot\readme.txt 
) 
goto masterlabel 
It missed the "%input%" script... how can I solve it? Thanks everyone

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Problem creating a batch file with a mother-batch file

#2 Post by aGerman » 17 Mar 2019 14:29

https://ss64.com/nt/syntax-esc.html
https://www.robvanderwoude.com/escapechars.php
The percent sign has a special meaning in Batch. It is used to expand variables and parameters to their value. In order to get a single percent sign as a literal expression you have to escape it. While most of other special characters require a caret (^), the percent sign has to be doubled.

Steffen

Mado91
Posts: 15
Joined: 16 Mar 2019 08:03

Re: Problem creating a batch file with a mother-batch file

#3 Post by Mado91 » 17 Mar 2019 23:58

It worked! thanks a lot :D

Post Reply