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
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
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
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback