{"id":102,"date":"2007-03-30T09:00:00","date_gmt":"2007-03-30T17:00:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/03\/30\/the-final-choice\/"},"modified":"2007-03-30T09:00:00","modified_gmt":"2007-03-30T17:00:00","slug":"the-final-choice","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/03\/30\/the-final-choice\/","title":{"rendered":"The Final Choice"},"content":{"rendered":"<p>Let&#8217;s wrap up our look at CHOICE.EXE and how to use it in batch files. I&#8217;ve shown you some basic examples but CHOICE has a few &#8220;advanced&#8221; features you might want to incorporate into your batch file.<\/p>\n<p>As I&#8217;ve explained before, menu choices by default are case-insensitive. However, you can enforce a case-sensitive choice with the \/CS switch:<\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">@echo off<br \/>echo a = Lower Case choice<br \/>echo A = Upper case choice<br \/>Choice \/c &#8220;aA&#8221; \/CS \/M &#8220;Make a choice&#8221; <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">if errorlevel 2 GOTO :Upper<br \/>if errorlevel 1 GOTO :Lower<br \/>GOTO :EOF <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">:Upper<br \/>echo Upper Case choice<br \/>GOTO :EOF <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">:Lower<br \/>echo Lower Case choice<br \/>GOTO :EOF <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">:EOF<\/font> <\/p>\n<p>The user&#8217;s choices are &#8220;a&#8221; or &#8220;A&#8221;. Again, the script jumps to the appropriate section depending on what was selected. <\/p>\n<p>There may be times in your batch file where you want to provide a menu choice, but don&#8217;t want to wait indefinitely. For those situations you will use a combination of \/T to specify a timeout value in seconds between 0 and 9999,&nbsp;and \/D to indicate the default value. The \/D value must be one of the options listed with \/C. <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">@echo off<br \/>Choice \/T 5 \/D Y \/M &#8220;Do you want to continue?&#8221; <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">if errorlevel 2 GOTO :NO<br \/>if errorlevel 1 GOTO :YES<br \/>GOTO :EOF <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">:NO<br \/>echo Not continuing<br \/>GOTO :EOF <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">:YES<br \/>echo Continuing<br \/>GOTO :EOF <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">:EOF<\/font><\/p>\n<p>This prompt will wait for 5 seconds for the user to make a choice. If they don&#8217;t respond by then, the script will force the default choice of Y which will evaulated just as if the user had typed Y at the choice prompt. <br \/>By now you should have enough information and samples on how to incorporate CHOICE into your batch files. If you ever forget the options, simpy run CHOICE \/? at a command prompt for syntax help. <\/p>\n<p>&nbsp;<\/p>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:83ce4693-13bd-4c78-881f-148d88247d3b\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\"><span class=\"sizeLess20\">Technorati tags: <\/span><a href=\"http:\/\/technorati.com\/tags\/CMD\" rel=\"tag\"><span class=\"sizeLess20\">CMD<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/choice\" rel=\"tag\"><span class=\"sizeLess20\">choice<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Commandline\" rel=\"tag\"><span class=\"sizeLess20\">Commandline<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Batch\" rel=\"tag\"><span class=\"sizeLess20\">Batch<\/span><\/a><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s wrap up our look at CHOICE.EXE and how to use it in batch files. I&#8217;ve shown you some basic examples but CHOICE has a few &#8220;advanced&#8221; features you might want to incorporate into your batch file.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18],"tags":[],"class_list":["post-102","post","type-post","status-publish","format-standard","hentry","category-batchcmd"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=102"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/102\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}