Append variables from one BATCH to another.

Posted on 2007-07-31
Last Modified: 2010-04-16
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


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!
Question by:Perkentha1
    LVL 33

    Expert Comment

    change this:

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

    to this:

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

    Accepted Solution

    Do this:

    echo. if /i "%%var1%%"=="answer" (goto:net) >> c:\temp.bat
    LVL 95

    Expert Comment

    by:Lee W, MVP
    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
    LVL 30

    Expert Comment

    leew, I thought that would be correct, but it doesn't appear to work:

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

    LVL 1

    Author Comment

    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!

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (…
    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now