choice

Windows CMD · Terminal · reference only

What it does

Shows a question with several single-key options and stores the chosen one in ERRORLEVEL, for use in .bat scripts.

Syntax

choice [/c opciones] [/m mensaje] [/t segundos /d opción] [/n] [/cs]

Options and parameters

  • /c opciones

    Letters allowed as an answer; YN by default, depending on the language.

  • /m mensaje

    Message shown before the question.

  • /n

    Hides the list of options in brackets.

  • /cs

    Makes it case-sensitive.

  • /t segundos

    Seconds to wait before choosing the default option.

  • /d opción

    Default option when time runs out; used with /t.

Usage examples

  • choice /c SN /m "¿Continuar?"

    Asks and waits for S or N.

  • choice /c SN /t 5 /d N

    Picks N automatically after 5 seconds if nobody answers.

  • if errorlevel 2 echo Has elegido No

    Detects that the second option was pressed.

  • choice /c ABC /n /m "Elige A, B o C: "

    Asks for a letter without showing the options.

Notes and common mistakes

  • ERRORLEVEL equals the position of the chosen option: 1 for the first, 2 for the second...
  • With if errorlevel you should test from highest to lowest, because the test means greater or equal.

Related commands