| 1. |
Solve : menu driven batch in dos? |
|
Answer» Hi,
C:\batch>type crazymenu.bat Code: [Select]ECHO off cls :start ECHO. ECHO 1. Hello 1 ECHO 2. Hello 2 ECHO 'Q' to exit ECHO. set /p choice=Enter choice: rem if not '%choice%'=='' set choice=%choice:~0,1% if "%choice%"=="1" goto HELLO1 if "%choice%"=="2" goto HELLO2 if "%choice%"=="Q" goto :end ECHO "%choice%" is not valid please try again ECHO. goto start :HELLO1 ECHO HI ( in Hello1 ) goto start :HELLO2 ECHO HOLA ( in Hello2) goto start :end C:\batch> crazymenu.bat Output: 1. Hello 1 2. Hello 2 'Q' to exit Enter choice: 1 HI ( in Hello1 ) 1. Hello 1 2. Hello 2 'Q' to exit Enter choice: 2 HOLA ( in Hello2) 1. Hello 1 2. Hello 2 'Q' to exit Enter choice: q "q" is not valid please try again 1. Hello 1 2. Hello 2 'Q' to exit Enter choice: Q C:\batch> Quote from: Sidewinder on March 04, 2010, 02:06:09 PM If you are booting to DOS 6.22, the /p switch is not valid on the set statement. exactly the problem i'm having. I tried looking both of those up and haven't found any solutions...<> 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: How do i get rid of this? Quote from: greg on March 04, 2010, 02:14:04 PM Greg, repeating your code won't work! You will know this if you ACTUALLY LOOK AT THE POSTS MADE BY PEOPLE OTHER THAN YOURSELF! Quote from: Sidewinder on March 04, 2010, 02:06:09 PM If you are booting to DOS 6.22, the /p switch is not valid on the set statement.Quote from: gonevcrazy on March 04, 2010, 04:11:26 PM 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. When DOS boots up, I'm sure you know it looks for Config.sys and autoexec.bat. 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. short answer: create an autoexec.bat file. Anyway, regarding the original question, pure DOS doesn't have a method of accepting user input built in; however, you can fake it. if you make a batch like this: Code: [Select]echo Batch Menu Selector echo Enter your choice: echo. echo 1. Start Windows echo 2. Return to DOS 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. To segregate this stuff from the rest of the system, you could even put it in it's own folder, say, C:\menu : so C:\menu would contain menu.bat, 1.bat, 2.bat, etc for each choice. Then, if you want the menu to start automatically, you do so via autoexec.bat, by adding this to the end of the file: Code: [Select]cd \menu menu Must be brain freeze. DOS 6.22 came with a utility called choice. It only accepts a single character, but that's all you really need for this situation. Type choice /? at the command prompt for details. 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. Good luck. http://www.shiningstar.net/geek/html/multiconfig.html Quote from: Helpmeh on March 04, 2010, 04:35:45 PM You will know this if you actually look at the posts made by people other than yourself. Thanks for the tip "Helpme" 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? Did the solution by Sidewinder work? (answer.com and input.com)? Quote from: Sidewinder on March 04, 2010, 05:04:11 PM Must be brain freeze. forgot about that myself as well. so it can be done in a single batch file... I don't know if I REMEMBER choice syntax perfectly, but here goes: Code: [Select]:showmenu cls echo Batch Menu echo Please enter a choice echo. echo A. Choice Number 1 echo B. Choice Number 2 echo C. Choice Number 3 echo. choice /c:ABC if ERRORLEVEL 3 GOTO CHOICEC if ERRORLEVEL 2 GOTO CHOICEB if ERRORLEVEL 1 GOTO CHOICEA goto showmenu :CHOICEA echo this would be choice A pause :CHOICEB echo this would be choice B pause :CHOICEC echo this would be choice C pause Thanks for the replies...I ended up REFORMATTING my USB dirive and put windows 98SE bootdisk on it and the date issue went away. 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. BC_Programmer: thanks...pretty hairy workaround...I'll give it a shot Quote from: gonevcrazy on March 04, 2010, 05:10:06 PM Thanks for the replies...I ended up reformatting my USB dirive and put windows 98SE bootdisk on it and the date issue went away. Oh, wait a MINUTE here... 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. Quote from: BC_Programmer on March 04, 2010, 05:16:35 PM Oh, wait a minute here... 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. fyi before WIN98SE boot, I used DOS6.22 boot from bootdisk.com to construct my USB drive. 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? |
|