1.

Solve : menu driven batch in dos?

Answer» <html><body><p>Hi,<br/><br/>I'm completely new to MS-DOS.<br/><br/>I have a Bootable USB drive with MS-DOS 6.22 on it.  My goal is to create a batch file that can be used in a menu-driven way.  I'm able to boot into the USB drive and have DOS running.<br/><br/>here is my code:<br/><br/>ECHO off<br/>cls<br/>:start<br/>ECHO.<br/>ECHO 1. Hello 1<br/>ECHO 2. Hello 2<br/>ECHO 'Q' to exit<br/>ECHO.<br/>set choice=<br/><strong>set /p choice=Enter choice: </strong><br/>if not '%choice%'=='' set choice=%choice:~0,1%<br/>if '%choice%'=='1' goto HELLO1<br/>if '%choice%'=='2' goto HELLO2<br/>ECHO "%choice%" is not valid please try again<br/>ECHO.<br/>goto start<br/>:HELLO1<br/>ECHO HI<br/>goto end<br/>:HELLO2<br/>ECHO HOLA<br/>goto end<br/>:end<br/><br/>The <a href="https://interviewquestions.tuteehub.com/tag/line-239358" style="font-weight:bold;" target="_blank" title="Click to know more about LINE">LINE</a> in bold is my problem.  When i run this batch, it never stops to wait for input, but proceeds to continue through the script.<br/><br/>is there any way for this to work?  please help!<br/><br/>I forgot to mention, this script works fine in Windows XP cmd.exe<br/>C:\batch&gt;type menu.bat<br/> Code: <a>[Select]</a>Echo off<br/><br/>:Start<br/>cls<br/>echo TITLE MAIN MENU<br/>ECHO 1) Sub_MenuA<br/>ECHO 2) Sub_MenuB<br/>ECHO 3) Internet<br/>ECHO 4) Quit<br/>ECHO.<br/>ECHO.<br/><br/>SET /p Option=Choice:<br/>if "%Option%"=="1" GOTO Sub_MenuA<br/>if "%Option%"=="2" GOTO Sub_MenuB<br/>if "%Option%"=="3" GOTO Internet<br/>if "%Option%"=="4" GOTO EOF<br/>Goto Start<br/><br/>:Sub_MenuA<br/>echo Sub_MenuA<br/>pause<br/>Goto Start<br/>:Sub_MenuB<br/>echo Sub_MenuB<br/>pause<br/>Goto Start<br/>:Internet<br/>echo Internet<br/>"c:\program files\internet explorer\iexplore.exe" http://www.google.com/<br/>Pause<br/>Goto Start<br/>:EOF<strong>Output:</strong><br/><br/><br/>C:\batch&gt; menu.bat<br/><br/>TITLE MAIN MENU<br/>1) Sub_MenuA<br/>2) Sub_MenuB<br/>3) Internet<br/>4) Quit<br/><br/><br/>Choice: 3<br/>Internet<br/>Press any key to continue . . .Thanks greg for the reply.<br/><br/>The problem I'm having is this: "SET /p Option=Choice:"<br/><br/>A little bit about my environment: I created a bootable USB drive with MSDOS 6.22.  I boot my system up and made sure my BIOS boots from the USB drive.<br/><br/>Once i'm at the command line, I try running my menu.bat, and it becomes an infinite loop, with the menu scrolling on my screen.  The reason is because it won't stop at "SET /p Option=Choice:" to wait for user input, but proceeds to continue through until it hits "Goto Start" and loops....forever.<br/><br/>is there a way to do this in a bootable USB environment where it will wait for user input?<br/>If you are booting to DOS 6.22, the <strong>/p </strong>switch is not valid on the <strong>set</strong> statement. <br/><br/>Back in the day, there were a couple of programs (<strong>answer.com</strong> and <strong>input.com</strong>) which would prompt for information and set an environment variable to the response. You might try Google for a download. Be sure to scan the programs with your AntiVirus program.<br/><br/>Good luck.  Quote from: gonevcrazy on March 04, 2010, 12:23:12 PM</p><blockquote><br/>here is my code:<br/><br/></blockquote> <br/>C:\batch&gt;type  crazymenu.bat<br/> Code: <a>[Select]</a>ECHO off<br/>cls<br/>:start<br/>ECHO.<br/>ECHO 1. Hello 1<br/>ECHO 2. Hello 2<br/>ECHO 'Q' to exit<br/>ECHO.<br/><br/>set /p choice=Enter choice:<br/>rem if not '%choice%'=='' set choice=%choice:~0,1%<br/>if "%choice%"=="1" goto HELLO1<br/>if "%choice%"=="2" goto HELLO2<br/>if "%choice%"=="Q" goto :end<br/>ECHO "%choice%" is not valid please try again<br/>ECHO.<br/>goto start<br/>:HELLO1<br/>ECHO HI ( in Hello1 )<br/>goto start<br/>:HELLO2<br/>ECHO HOLA ( in Hello2)<br/>goto start<br/>:end<br/>C:\batch&gt; crazymenu.bat<br/><br/><strong>Output:</strong><br/><br/>1. Hello 1<br/>2. Hello 2<br/>'Q' to exit<br/><br/>Enter choice: 1<br/>HI ( in Hello1 )<br/><br/>1. Hello 1<br/>2. Hello 2<br/>'Q' to exit<br/><br/>Enter choice: 2<br/>HOLA ( in Hello2)<br/><br/>1. Hello 1<br/>2. Hello 2<br/>'Q' to exit<br/><br/>Enter choice: q<br/>"q" is not valid please try again<br/><br/><br/>1. Hello 1<br/>2. Hello 2<br/>'Q' to exit<br/><br/>Enter choice: Q<br/>C:\batch&gt; Quote from: Sidewinder on March 04, 2010, 02:06:09 PM<blockquote>If you are booting to DOS 6.22, the <strong>/p </strong>switch is not valid on the <strong>set</strong> statement. <br/><br/>Back in the day, there were a couple of programs (<strong>answer.com</strong> and <strong>input.com</strong>) which would prompt for information and set an environment variable to the response. You might try Google for a download. Be sure to scan the programs with your AntiVirus program.<br/><br/>Good luck.  <br/></blockquote> <br/>exactly the problem i'm having.  I tried looking both of those up and haven't found any solutions...&lt;&gt;<br/><br/>Another issue i'm having is whenever I've successfully booted off my USB drive into DOS, i always get asked for the current date and time.  Below is an image of what I'm talking about:<br/><br/><br/><br/>How do i get rid of this? Quote from: greg on March 04, 2010, 02:14:04 PM<blockquote></blockquote> Greg, repeating your code won't work! You will know this if you ACTUALLY LOOK AT THE POSTS MADE BY PEOPLE OTHER THAN YOURSELF!<br/> Quote from: Sidewinder on March 04, 2010, 02:06:09 PM<blockquote>If you are booting to DOS 6.22, the <strong>/p </strong>switch is not valid on the <strong>set</strong> statement. <br/><br/>Back in the day, there were a couple of programs (<strong>answer.com</strong> and <strong>input.com</strong>) which would prompt for information and set an environment variable to the response. You might try Google for a download. Be sure to scan the programs with your AntiVirus program.<br/><br/>Good luck.  <br/></blockquote> Quote from: gonevcrazy on March 04, 2010, 04:11:26 PM<blockquote>Another issue i'm having is whenever I've successfully booted off my USB drive into DOS, i always get asked for the current date and time. <br/>How do i get rid of this? <br/></blockquote> <br/>When DOS boots up, I'm sure you know it looks for Config.sys and autoexec.bat.<br/><br/>If DOS cannot find an autoexec.bat, it gets suspicious, and starts to doubt itself, so it asks you if it knows the correct time.<br/><br/>short answer: create an autoexec.bat file.<br/><br/><br/>Anyway, regarding the original question, pure DOS doesn't have a method of accepting user input built in; however, you can fake it.<br/><br/>if you make a batch like this:<br/><br/> Code: <a>[Select]</a>echo Batch Menu Selector<br/>echo Enter  your choice:<br/>echo.<br/>echo 1. Start Windows<br/>echo 2. Return to DOS<br/><br/>and then, for each choice, you create a batch file- 1.bat, 2.bat, etc. so when they enter their choice, it starts that batch file.<br/><br/>To segregate this stuff from the rest of the system, you could even put it in it's own folder, say, C:\menu :<br/><br/>so C:\menu would contain menu.bat, 1.bat, 2.bat, etc for each choice.<br/><br/>Then, if you want the menu to start automatically, you do so via autoexec.bat, by adding this to the end of the file:<br/><br/> Code: <a>[Select]</a>cd \menu<br/>menu<br/>Must be brain freeze. <br/><br/>DOS 6.22 came with a utility called <strong>choice</strong>. It only accepts a single character, but that's all you really need for this situation. Type <strong>choice /?</strong> at the command prompt for details.<br/><br/>Date and time: check the autoexec.bat file (on the USB drive) you're using and see if those two commands are included. If so that's where the prompts are coming from. How old is this machine? The battery may be dead. Modern OSes can get the date/time from a time server...DOS is not a modern OS. <br/><br/>Good luck.  <a href="http://www.shiningstar.net/geek/html/multiconfig.html">http://www.shiningstar.net/geek/html/multiconfig.html</a> Quote from: Helpmeh on March 04, 2010, 04:35:45 PM<blockquote> You will know this if you actually look at the posts made by people other than yourself.<br/></blockquote> <br/>Thanks for the tip "Helpme"<br/><br/>I have now looked at the complete thread for a solution by "Helpme" and cannot find it.  Did "Helpme" post the solution in another thread?<br/><br/>Did the solution by Sidewinder work? (answer.com and input.com)? Quote from: Sidewinder on March 04, 2010, 05:04:11 PM<blockquote>Must be brain freeze. <br/><br/>DOS 6.22 came with a utility called <strong>choice</strong>. It only accepts a single character, but that's all you really need for this situation. Type <strong>choice /?</strong> at the command prompt for details.<br/><br/></blockquote> <br/>forgot about that myself as well.<br/><br/>so it can be done in a single batch file... I don't know if I <a href="https://interviewquestions.tuteehub.com/tag/remember-621937" style="font-weight:bold;" target="_blank" title="Click to know more about REMEMBER">REMEMBER</a> choice syntax perfectly, but here goes:<br/><br/><br/> Code: <a>[Select]</a>:showmenu<br/>cls<br/>echo Batch Menu<br/>echo Please enter a choice<br/>echo.<br/>echo A. Choice Number 1<br/>echo B. Choice Number 2<br/>echo C. Choice Number 3<br/>echo.<br/>choice /c:ABC<br/>if ERRORLEVEL 3 GOTO CHOICEC<br/>if ERRORLEVEL 2 GOTO CHOICEB<br/>if ERRORLEVEL 1 GOTO CHOICEA<br/>goto showmenu<br/>:CHOICEA<br/>echo this would be choice A<br/>pause<br/>:CHOICEB<br/>echo this would be choice B<br/>pause<br/>:CHOICEC<br/>echo this would be choice C<br/>pause<br/>Thanks for the replies...I ended up <a href="https://interviewquestions.tuteehub.com/tag/reformatting-7710114" style="font-weight:bold;" target="_blank" title="Click to know more about REFORMATTING">REFORMATTING</a> my USB dirive and put windows 98SE bootdisk on it and the date issue went away.<br/><br/>As for the my original question...still no dice.  "Choice /?" comes back with "Bad File or Command".  I'm thinking during my creation of boot disk (I used HP Disk Storage Format Tool along with Windows98SE.img from bootdisk.com) that it only installs command.exe and some other files, enough to get it up and running, but none of the bells and whistles.<br/><br/>BC_Programmer: thanks...pretty hairy workaround...I'll give it a shot Quote from: gonevcrazy on March 04, 2010, 05:10:06 PM<blockquote>Thanks for the replies...I ended up reformatting my USB dirive and put windows 98SE bootdisk on it and the date issue went away.<br/><br/>As for the my original question...still no dice.  "Choice /?" comes back with "Bad File or Command".  I'm thinking during my creation of boot disk (I used HP Disk Storage Format Tool along with Windows98SE.img from bootdisk.com) that it only installs command.exe and some other files, enough to get it up and running, but none of the bells and whistles.<br/><br/>BC_Programmer: thanks...pretty hairy workaround...I'll give it a shot<br/></blockquote> <br/>Oh, wait a <a href="https://interviewquestions.tuteehub.com/tag/minute-767068" style="font-weight:bold;" target="_blank" title="Click to know more about MINUTE">MINUTE</a> here...<br/><br/>the Windows98 Boot disk is not a actual DOS installation, so it doesn't contain All of the necessary DOS files. for example, in my virtual Machine running DOS 6.22, my DOS folder is slightly <a href="https://interviewquestions.tuteehub.com/tag/larger-1067345" style="font-weight:bold;" target="_blank" title="Click to know more about LARGER">LARGER</a> then 5MB, which wouldn't fit on a floppy disk. the boot disk just contains the "important" stuff.<br/><br/> Quote from: BC_Programmer on March 04, 2010, 05:16:35 PM<blockquote>Oh, wait a minute here...<br/><br/>the Windows98 Boot disk is not a actual DOS installation, so it doesn't contain All of the necessary DOS files. for example, in my virtual Machine running DOS 6.22, my DOS folder is slightly larger then 5MB, which wouldn't fit on a floppy disk. the boot disk just contains the "important" stuff.<br/><br/><br/></blockquote> <br/>Yah it's beginning to dawn on me that my goal can't be reached via booting off the USB drive due to the fact that it's only used to boot and doesn't contain any of the extra tools like a full DOS 6.22 would have.   <br/><br/>fyi before WIN98SE boot, I used DOS6.22 boot from bootdisk.com to construct my USB drive.<br/><br/>I guess my follow-up question would be could I copy/paste those files (i.e. CHOICE.EXE or FDISK.EXE, for sake of example) onto my USB drive and run 'em like I would a command?</body></html>


Discussion

No Comment Found