Windows batch file - second prompt doesn't work [duplicate]

  • 1 year ago
Comment

1 / 1

If the second prompt in your Windows batch file isn't working, it's likely due to the fact that the set /p command doesn't clear the input buffer. Here's an example of how this issue can occur:

batch
@echo off

set /p var1=Enter value 1:
echo Value 1 is %var1%

set /p var2=Enter value 2:
echo Value 2 is %var2%

In this example, the first prompt will work correctly and allow the user to input a value. However, when the second prompt appears, the input buffer still contains the value entered in the first prompt, and the user won't be able to enter a new value.

To fix this issue, you can add the cls command after the first set /p command to clear the screen and input buffer, like this:

batch
@echo off

set /p var1=Enter value 1:
echo Value 1 is %var1%

cls

set /p var2=Enter value 2:
echo Value 2 is %var2%

This will clear the input buffer and allow the user to enter a new value in the second prompt. Alternatively, you can use the choice command to prompt the user for a choice or a Y/N response, which automatically clears the input buffer.