Home > Uncategorized > Differences between CHOICE command in Batch files

Differences between CHOICE command in Batch files

Batch files may be arcane, but they serve well for quick & nasty build scripts. One point to note that I fell into a trap today is the difference in the implementation of the CHOICE command (prompting the user for input) between Windows 9x and Windows 2000/XP. – Alot of documentation on Batch files is quite old, and thus doesn’t mark any difference
 
Windows 9x:
CHOICE /C:123 /N Please choose a menu option.
IF ERRORLEVEL == 3 GOTO LIVE
IF ERRORLEVEL == 2 GOTO BACKUP
IF ERRORLEVEL == 1 GOTO LOCAL
EXIT
 
Windows 2000/XP:
set choice=
set /p choice=Please choose a menu option.
if not ‘%choice%’==” set choice=%choice:~0,1%
if ‘%choice%’==’1’ goto LOCAL
if ‘%choice%’==’2’ goto BACKUP
if ‘%choice%’==’3’ goto LIVE
EXIT
 
Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: