1.

Solve : menu driven batch in dos?

Answer»

Hi,

I'm completely new to MS-DOS.

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.

here is my code:

ECHO off
cls
:start
ECHO.
ECHO 1. Hello 1
ECHO 2. Hello 2
ECHO 'Q' to exit
ECHO.
set choice=
set /p choice=Enter choice:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto HELLO1
if '%choice%'=='2' goto HELLO2
ECHO "%choice%" is not valid please try again
ECHO.
goto start
:HELLO1
ECHO HI
goto end
:HELLO2
ECHO HOLA
goto end
:end

The LINE in bold is my problem.  When i run this batch, it never stops to wait for input, but proceeds to continue through the script.

is there any way for this to work?  please help!

I forgot to mention, this script works fine in Windows XP cmd.exe
C:\batch>type menu.bat
Code: [Select]Echo off

:Start
cls
echo TITLE MAIN MENU
ECHO 1) Sub_MenuA
ECHO 2) Sub_MenuB
ECHO 3) Internet
ECHO 4) Quit
ECHO.
ECHO.

SET /p Option=Choice:
if "%Option%"=="1" GOTO Sub_MenuA
if "%Option%"=="2" GOTO Sub_MenuB
if "%Option%"=="3" GOTO Internet
if "%Option%"=="4" GOTO EOF
Goto Start

:Sub_MenuA
echo Sub_MenuA
pause
Goto Start
:Sub_MenuB
echo Sub_MenuB
pause
Goto Start
:Internet
echo Internet
"c:\program files\internet explorer\iexplore.exe" http://www.google.com/
Pause
Goto Start
:EOFOutput:


C:\batch> menu.bat

TITLE MAIN MENU
1) Sub_MenuA
2) Sub_MenuB
3) Internet
4) Quit


Choice: 3
Internet
Press any key to continue . . .Thanks greg for the reply.

The problem I'm having is this: "SET /p Option=Choice:"

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.

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.

is there a way to do this in a bootable USB environment where it will wait for user input?
If you are booting to DOS 6.22, the /p switch is not valid on the set statement.

Back in the day, there were a couple of programs (answer.com and input.com) 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.

Good luck.  Quote from: gonevcrazy on March 04, 2010, 12:23:12 PM


here is my code:


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.

Back in the day, there were a couple of programs (answer.com and input.com) 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.

Good luck. 

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.

Back in the day, there were a couple of programs (answer.com and input.com) 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.

Good luck. 
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. 
How do i get rid of this?

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.

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.


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.

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

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...

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.



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?


Discussion

No Comment Found