mardi 3 février 2015

Cannot take user input in batch file while in if statement

I want to get input from user in a batch file but while it works fine when I am outside of if statement, when I get inside it doesn't get user's input.



@echo off

set /p flag=Enter letter 'y':

echo %flag%

if %flag% == y (
set /p flag2=Enter random string:

echo flag2: %flag2%
)

pause


In the above example after I enter 'y' for the first prompt, it prints the contents of %flag% but then in the second prompt inside if statement, the %flag2% gets no value.


Output:



Enter letter 'y': y
y
Enter random string:lalala
flag2:
Press any key to continue . . .


Why is this happening?


Aucun commentaire:

Enregistrer un commentaire