[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Append variables from one BATCH to another.

I need to carry over variables from one bat file to another for instance

Bat 1 executes

Echo.set /p var1:"questestion?" >> c:\temp.bat
echo. if /i "%var1%"=="answer" (goto:net) >> c:\temp.bat

Problem:  

echo. /i "%var1%"=="answer" (goto:net) >> c:\temp.bat
write out like this
if /i ""=="answer" (goto:net)
I need the %var1% to carry over too!
0
Perkentha1
Asked:
Perkentha1
1 Solution
 
knightEknightCommented:
change this:

   Echo.set /p var1:"questestion?" >> c:\temp.bat

to this:

   Echo.set /p var1="questestion?" >> c:\temp.bat
0
 
SteveGTRCommented:
Do this:

echo. if /i "%%var1%%"=="answer" (goto:net) >> c:\temp.bat
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
That's one problem...

And to answer your question, use the escape character and don't use a colon in the gotos.

echo. /i "^%var1^%"=="answer" (goto net) >> c:\temp.bat
0
 
SteveGTRCommented:
leew, I thought that would be correct, but it doesn't appear to work:

 /i "^"=="answer" (goto net)

0
 
Perkentha1Author Commented:
I recieved the same results, %%var%% works,  I woulda have never thought to do that even though it did cross my mind.

Thanks for the help both of you!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now