Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
choice batch command is not working in XP. Why ? Is there any other way of putting questions to users ??!!

choice is a DOS/Windows 9X/Windows ME thing. It was never available on NT, 2K or XP. You could try one of the methods in Secret_Doom's website
http://www.batch.hpg.ig.com.br/index.htm

You might try posting this in the Windows XP forum, since you're using Windows XP and not DOS.
I'm sure there's probably more than a few XP gurus who read and post to the DOS forum, but you'll probably have better luck posting this to a forum dedicated for the operating system you're using.
Windows XP does include two command consoles that look like the DOS UI and accept many DOS commands as well as something called the NTVDM (NT Virtual Dos Machine), which is capable of emulating a DOS environment, allowing many DOS programs to run under XP, but Windows XP is not DOS and does not include DOS. It's quite a different animal altogether and shares none of the DOS code base.

Choice.com is an external dos command. Just copy into one of the directories in your path (I.E. your windows directory) and it should work fine. I use it all the time in win2k. Just copy it from a windows 95/98 installation (usually resides in c:\windows\command).
HTH,
Michael

Thanks for pointing my site, cup, but I don't think he will be able to use any of my scripts (DOS scripts, not for NT) for what he wants, since both methods I use to get user input (choice.com and "FC.exe con nul") aren't avaliable on NT systems.
Michael's tip is valid, but you wouldn't be able to make a stand-alone batch file (if you send it to someone else who uses NT, this person would have to get CHOICE.COM just as you did).
I know two good work arounds for that.
First method: Use SET/P, like this:
@echo off
:choice
echo Choose:
echo [1] Option A
echo [2] Option B
:input
SET CHOICE=
SET /P C=
for %%? in (1 2) do if "%C%"=="%%?" set CH=%%?
if "%CH%"=="" goto input
set C=
echo User choice: %CH%Watch out for line wrapping!
This method will only work on NT. It will fail on dos systems (DOS, Win9x, WinME)Second method:
@echo off
:: Thanks to Laurence Soucy for the following assembler code
echo e100 B4 00 CD 16 88 E0 B4 4C CD 21> %temp%.\scan.com
for %%? in (rcx A w q) do echo %%?>> %temp%.\scan.com
type %temp%.\scan.com |DEBUG %temp%.\scan.com > nul
:choice
echo Choose:
echo [1] Option A
echo [2] Option B
:input
set CH=
call %temp%.\scan.com
if errorlevel=2 if not errorlevel=3 set CH=1
if errorlevel=3 if not errorlevel=4 set CH=2
if "%CH%"=="" goto input
del %temp%.\scan.com
echo User choice: %CH%Watch out for line wrapping!
This second method works for both NT and DOS.SCAN.COM will return a certain errorlevel for each key entered. In order to identify the errorlevel returned by a certain key:
1. Run SCAN.COM
2. Hit the desired key
3. Type "ECHO %ERRORLEVEL%" at the command promptThe errorlevel for the "1" key which is not in the numpad is 2. But the errorlevel for the "1" key from numpad is 79. So, the above script will only accept the 1 and 2 keys pressed from out the numpad.
PS: This tip about "echo %errorlevel%" is only valid for NT systems.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |