• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Batch File user input question

Skyzoomer

Senior member
Running WinXP and Vista. Could someone post the batch file code that will allow just pressing the Enter key to accept the default value?

Example code:
Set /p Choice=Enter the number of copies and press Enter:

If a number is typed and user presses Enter, all is well.
But if the user just presses Enter without typing anything, the batch file closes without giving me a chance to process his action.

How can I code this so the user can just press Enter to accept the default value?

Thanks,
Sky
 
Found that the batch file does not exit because "Enter" was pressed without typing a character first. The batch file exits when it tries my test to see if the user didn't type anything.

Here's some sample code:

@echo off
Set /p Choice=Enter the number of copies and press Enter:
if %Choice%=="" echo Only Enter key pressed.
echo Got this far without batch file quitting. Choice was %Choice%
pause

If I type a number or letter, line-4 displays the character I typed. But if I don't type anything and just press "Enter", the batch file exits without ever getting to line-4.

Any ideas on how to test that only the Enter key was pressed?
 
Back
Top