Problem entering user into my batch file

here is the piece of code giving me problems:

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, regardless of the input, the batch file exits. Why is this happening (delete andcontinue is never achieved)?

Thank!

+3
if-statement batch-file user-input
May 27 '09 at 15:29
source share
1 answer

Try using the delayed extension 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 expand when reading a command. The set of commands between parens is considered as one command, so delBuild does not exist when you move on to testing. When the extension is delayed, the variables expand when the command is executed, therefore, during the test, delBuild matters.

+3
May 27 '09 at 16:33
source share



All Articles