Need help with Choice command for batch fille

March 3, 2010 at 18:03:17
Specs: Windows XP
I dont know what to do it is freaking me out!
I made a batch file at school that had a choice command in it. It worked great at first but a day later it said "choice" is not a valid command or something like that. Know i tried it at home and it still does not work! here is the code i am trying...

@ECHO OFF
REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
:BEGIN
CLS
REM - THE BELOW LINE GIVES THE USER 3 CHOICES (DEFINED AFTER /C:)
CHOICE /N /C:123 PICK A NUMBER (1, 2, or 3)%1
REM - THE NEXT THREE LINES ARE DIRECTING USER DEPENDING UPON INPUT
IF ERRORLEVEL ==3 GOTO THREE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE
GOTO END
:THREE
ECHO YOU HAVE PRESSED THREE
GOTO END
:TWO
ECHO YOU HAVE PRESSED TWO
GOTO END
:ONE
ECHO YOU HAVE PRESSED ONE
:END


See More: Need help with Choice command for batch fille

Report •


#1
March 3, 2010 at 18:15:55
The choice command isn't available on nt/2k/xp by default. I *think* it was re-introduced with vista.

If you want to use choice on these systems you will need a binary with the script(choice.com or choice.exe).

The other option is to use "set /p"(win2k an up), but it will need some input validation.


Report •

#2
March 3, 2010 at 19:11:14
what do you mean by "If you want to use choice on these systems you will need a binary with the script(choice.com or choice.exe)." I am new and do not under stand i just want to make something so i need to press one button to make it work.

thanks


Report •

#3
March 3, 2010 at 23:33:53
In batch script there are two types of commands - internal and external commands.

Internal commands are built into the command processor(cmd.exe for nt based windows - nt/2k/xp/2k3/vista/.....). This means that the command is handled without calling any other programs. Examples are echo, dir and set.

External commands are actually programs in themselves that are called by the command processor. Microsoft ships a few of these with their os', but it's possible to add more external commands to the system, these extra programs should either be in the same directory as the script that uses them or one of the %path% directories. Examples of included external commands are find, ping and xcopy.

"Choice" is an external command and since Microsoft didn't include it in nt, 2k or xp. The only way to use it is to add it to the system(or the media the script using it is run from).

Basically all that means it that means is if you want to use it you must bring your own copy.

"Choice" is actually quite an old external command, it actually started life in MS-DOS. The old versions are "choice.com"(probably won't work in 64bit systems) and the newer versions are "choice.exe"(should work on 64bit systems).

The bottom line: If you want to use choice on xp get a copy from somewhere and stick it in the same folder as your script.


Report •

Related Solutions

#4
March 4, 2010 at 01:42:04
Really a educative and informative post, the post is good in all regards,I am glad to read this post.

The Weider X-Factor


Report •

#5
March 4, 2010 at 12:48:16
You can find choice.com here:
http://hp.vector.co.jp/authors/VA00...

You can also put it in the ?:\windows folder and it will be available no matter where your script is.


Report •

#6
March 4, 2010 at 23:17:49
CHOICE.COM will **work** in NT/XP but may trash your prompt.

I recommend you stick with CHOICE.EXE

Judago, good, clear explanation.


=====================================
Helping others achieve escape felicity

M2


Report •

#7
March 5, 2010 at 01:03:17
Thanks M2 and kirstenheny!

Report •

#8
March 8, 2010 at 07:45:18
Thanks for all the help. I got it to work.

thanks,
kyle


Report •

Ask Question