views:

1691

answers:

3

Is there a way to prompt users for input (ie: Yes/No) from a Dos batch script that works on XP and Windows 2003 server? It seems some commands (ie: choice) only work on one OS and not others.

+5  A: 

Use the SET command with the /P switch.

Nick Fortescue
+2  A: 
SET /P RESULT=Y or N?
ECHO %RESULT%
aphoria
+1  A: 

Note that the SET /P command does not support all the same features as the CHOICE command. Namely:

  • It doesn't restrict the user to entering a valid value
  • The user has to press enter
  • You have to check for casing differences (e.g. "A" vs "a")
  • There is no way to default to a certain choice after a certain amount of time

For these reasons, I still prefer to use the CHOICE command rather than the SET /P command. To do this, you just need to include CHOICE.COM along with your batch file. You can download CHOICE.COM from Microsoft via the MS-DOS 6.22 Supplemental Disk. Here's the link:

http://support.microsoft.com/kb/117600

James Messinger