Draft for Information Only
Content
MS DOS Command: CHOICE
MS DOS Command: CHOICEReference from Microsoft MS-DOS cmd help DescriptionPrompts the user to make a choice in a batch program. Displays a specified prompt and pauses for the user to choose from among a specified set of keys. You can use this command only in batch programs. For more information on the ERRORLEVEL parameter, see CHOICE--Note and the IF command. SyntaxCHOICE [/C[:]keys] [/N] [/S] [/T[:]c,nn] [text] Parameters
Switches
RemarksERRORLEVEL parametersThe first key you assign returns a value of 1, the second a value of 2, the third a value of 3, and so on. If the user presses a key that is not among the keys you assigned, CHOICE sounds a warning beep (that is, it sends a BEL, or 07h, character to the console). If CHOICE detects an error condition, it returns an ERRORLEVEL value of 255. If the user presses CTRL+BREAK or CTRL+C, CHOICE returns an ERRORLEVEL value of 0. When you use ERRORLEVEL parameters in a batch program, list them in decreasing order. ExamplesWhat the user sees when you use CHOICE in a batch file If you use the following syntax in a batch file, choice /c:ync the user sees the following when CHOICE is started: [Y,N,C]? If you add text to the syntax, choice /c:ync Yes, No, or Continue the user sees the following when CHOICE is started: Yes, No, or Continue [Y,N,C]? What the user sees if you leave out a prompt If, as in the following example, you use the /N switch to leave out the prompt in a batch program, choice /n Yes, No, or Continue? the user sees only the text you specified when CHOICE is started: Yes, No, or Continue? What the user sees if you use the T switch If you use the following syntax in a batch program, choice /c:ync /t:n,5 the user sees the following when CHOICE is started: [Y,N,C]? If, after 5 seconds, the user hasn't pressed a key, CHOICE chooses N and returns an ERRORLEVEL value of 2. If the user presses a key before 5 seconds, CHOICE returns the value corresponding to the user's choice. To have the option of defragmenting drive C when you start your computer, you could add the following lines to your AUTOEXEC.BAT file: choice Defrag drive /ty,5 if errorlevel 2 goto SkipDefrag defrag c: :SkipDefrag If you press N within 5 seconds, DEFRAG will not run and CHOICE returns an ERRORLEVEL value of 2. If you do not press N within 5 seconds, or if you choose Y, DEFRAG is run on drive C. Using CHOICE in a batch program The following batch program demonstrates using the CHOICE option to select one of three programs: MS-DOS Editor, Microsoft Anti-Virus, or Microsoft Backup. Notice that the IF ERRORLEVEL statements are listed in decreasing order. MS-DOS will consider the IF statement true if the ERRORLEVEL parameter returned by CHOICE is greater than or equal to the parameter specified in the IF command. @echo off cls echo. echo A Microsoft Editor echo B Microsoft Anti-Virus echo C Microsoft Backup echo. choice /c:abc Choose an option if errorlevel 3 goto MSBackup if errorlevel 2 goto Msav if errorlevel 1 goto Edit
:Edit edit goto End
:Msav msav goto End
:Msbackup msbackup goto End
:End ©sideway ID: 110700141 Last Updated: 7/22/2011 Revision: 0 Latest Updated Links
![]() ![]() ![]() ![]() ![]() |
![]() Home 5 Business Management HBR 3 Information Recreation Hobbies 8 Culture Chinese 1097 English 339 Travel 18 Reference 79 Computer Hardware 254 Software Application 213 Digitization 37 Latex 52 Manim 205 KB 1 Numeric 19 Programming Web 289 Unicode 504 HTML 66 CSS 65 SVG 46 ASP.NET 270 OS 431 DeskTop 7 Python 72 Knowledge Mathematics Formulas 8 Set 1 Logic 1 Algebra 84 Number Theory 206 Trigonometry 31 Geometry 34 Calculus 67 Engineering Tables 8 Mechanical Rigid Bodies Statics 92 Dynamics 37 Fluid 5 Control Acoustics 19 Natural Sciences Matter 1 Electric 27 Biology 1 |
Copyright © 2000-2025 Sideway . All rights reserved Disclaimers last modified on 06 September 2019