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?