3

here is the portion of code giving me trouble:

IF EXIST TH_BUILD_* (
ECHO A current build of Test Harness exists.
set /p delBuild=Delete preexisting build [y/n]?: 
if "%delBuild%"=="y" (GOTO deleteandcontinue) else ( EXIT)
)

For some reason, no matter the input, the batch file exits. Why is this happening (deleteandcontinue is never reached)?

Thanks!

1 Answer 1

3

Try using delayed expansion when testing delBuild:

setlocal enableextensions enabledelayedexpansion

IF EXIST TH_BUILD_* (
    ECHO A current build of Test Harness exists.
    set /p delBuild=Delete preexisting build [y/n]?: 
    if "!delBuild!"=="y" (
        GOTO deleteandcontinue
    ) else (
        exit
    )
)

:deleteandcontinue
@echo At deleteandcontinue

%var% variables are expanded when the command is read. The set of commands between the parens are treated as a single command, so delBuild doesn't exist when you go to test. With the delayed expansion, the variables are expanded when the command is executed, so at the time of the test, delBuild has a value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.