CHOICE

The CHOICE command was introduced in MS-DOS 6 and is still available in MS-DOS 7 (Windows 95/98).

As of Windows NT 4, CHOICE is no longer a part of the standard distribution. It is, however, available as part of the Windows NT 4 Resouce Kit.

On the other hand, if you still have that old unused MS-DOS 6 or Windows 95/98 version lying around, you can use the CHOICE.COM from that version instead. (*)
Just copy it to a directory that is in your PATH.

Note: 16-bit DOS versions will not work in 64-bit Windows versions.

CHOICE is available again in Windows Vista and later versions.

Syntax:

     Waits for the user to choose one of a set of choices.
 
  CHOICE  [ /C[:]choices ]  [ /N ]  [ /S ]  [ /T[:]c,nn ] text
 
       /C:choices      Specifies allowable keys.
Default for English versions is YN
  /N   Do not display choices an ? at end of prompt string.
  /S or /CS   Treat choice keys as case sensitive.
Up to (and including) the Resource Kit versions, use /S.
In Windows 7 use /CS.
  /T:c,nn   Default choice to c after nn seconds.
  text   Prompt string to display.
 
     ERRORLEVEL is set to the offset of the key the user presses on choices.

Examples:

 

At the bottom of my errorlevel page you can find an example that uses CHOICE to convert redirected output to an errorlevel.

On my wait page CHOICE's time-out option (/T) is used to insert a delay in batch files.

An ingenious way to use CHOICE is demonstrated by Laurence Soucy's version of BootDriv.bat.

CHOICE can also be used to strip or replace certain characters from text strings, as explained on my Batch HowTo page, the CD-ROM example of my Solutions found at alt.msdos.batch page, and in the GetPorts example.

 

My PMCHOICE for NT, written in both KiXtart and batch, gives NT users almost the same functionality.
I haven't figured out a way to implement the time-out period in KiXtart, though pressing Enter will result in the default value, if specified.

 

My CHOICE.EXE for OS/2, written in Rexx and compiled by RXCLS, gives OS/2 users the same functionality.
To use the /T switch you need Quercus Systems' RexxLib, though.

 

I also "ported" the CHOICE command to Rexx and Perl, though the latter does have some limitations.


page last uploaded: 27 August 2012, 13:15