Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: menu driven batch in dos  (Read 21751 times)

0 Members and 1 Guest are viewing this topic.

gonevcrazy

    Topic Starter


    Greenhorn

    menu driven batch in dos
    « on: March 04, 2010, 12:23:12 PM »
    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

    greg



      Intermediate

      Thanked: 7
      Re: menu driven batch in dos
      « Reply #1 on: March 04, 2010, 12:54:54 PM »

      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
      :EOF
      Output:


      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 . . .
      Have a Nice Day

      gonevcrazy

        Topic Starter


        Greenhorn

        Re: menu driven batch in dos
        « Reply #2 on: March 04, 2010, 01:01:26 PM »
        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?

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: menu driven batch in dos
        « Reply #3 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.  8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        greg



          Intermediate

          Thanked: 7
          Re: menu driven batch in dos
          « Reply #4 on: March 04, 2010, 02:14:04 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>
          Have a Nice Day

          gonevcrazy

            Topic Starter


            Greenhorn

            Re: menu driven batch in dos
            « Reply #5 on: March 04, 2010, 04:11:26 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.  8)

            exactly the problem i'm having.  I tried looking both of those up and haven't found any solutions...<<sigh>>

            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?

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: menu driven batch in dos
            « Reply #6 on: March 04, 2010, 04:35:45 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!
            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.  8)
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: menu driven batch in dos
            « Reply #7 on: March 04, 2010, 04:59:20 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 <really> 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
            I was trying to dereference Null Pointers before it was cool.

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: menu driven batch in dos
            « Reply #8 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.

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

            Good luck.  8)
            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            Computer_Commando



              Hacker
            • Thanked: 494
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10

            greg



              Intermediate

              Thanked: 7
              Re: menu driven batch in dos
              « Reply #10 on: March 04, 2010, 05:07:43 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)?
              Have a Nice Day

              BC_Programmer


                Mastermind
              • Typing is no substitute for thinking.
              • Thanked: 1140
                • Yes
                • Yes
                • BC-Programming.com
              • Certifications: List
              • Computer: Specs
              • Experience: Beginner
              • OS: Windows 11
              Re: menu driven batch in dos
              « Reply #11 on: March 04, 2010, 05:08:07 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
              I was trying to dereference Null Pointers before it was cool.

              gonevcrazy

                Topic Starter


                Greenhorn

                Re: menu driven batch in dos
                « Reply #12 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

                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: menu driven batch in dos
                « Reply #13 on: March 04, 2010, 05:16:35 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.

                I was trying to dereference Null Pointers before it was cool.

                gonevcrazy

                  Topic Starter


                  Greenhorn

                  Re: menu driven batch in dos
                  « Reply #14 on: March 04, 2010, 05:22:32 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?

                  BC_Programmer


                    Mastermind
                  • Typing is no substitute for thinking.
                  • Thanked: 1140
                    • Yes
                    • Yes
                    • BC-Programming.com
                  • Certifications: List
                  • Computer: Specs
                  • Experience: Beginner
                  • OS: Windows 11
                  Re: menu driven batch in dos
                  « Reply #15 on: March 04, 2010, 05:27:10 PM »
                  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?

                  Depends where you source the files from.

                  a DOS installation is really just what you have- you just don't have those files- the external commands, such as choice, installed on the drive. if you do copy them you will need to get the right version. If your using the win98SE DOS you'll need to get the files from Win98SE.
                  I was trying to dereference Null Pointers before it was cool.