Computing.Net > Forums > Disk Operating System > Menu in a batch file

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Menu in a batch file

Reply to Message Icon

Original Message
Name: Eric
Date: August 7, 2002 at 22:32:37 Pacific
Subject: Menu in a batch file
Comment:

I've created a batch file with a menu inside, 1 to 7 choices. When I execute the batch file, the DOS window pops and closes right away and I don't know why. I've even done a search on google for batch files with menus and they all do the same thing. Could it be Windows XP???


Report Offensive Message For Removal


Response Number 1
Name: Hans
Date: August 8, 2002 at 01:59:17 Pacific
Reply: (edit)

Post your batchfile so we can have a look at it. There are so many things what can be wrong.

I don't think this is because WinXP but I'm not sure.


Report Offensive Follow Up For Removal

Response Number 2
Name: Secret_Doom
Date: August 8, 2002 at 10:44:56 Pacific
Reply: (edit)

A batch menu like this will likely open and close instantly on WinXP:

@echo off
echo Choose:
echo [1] Option 1
echo [2] Option 2
CHOICE /c:12

While in Win9x the CHOICE.COM command is present by default and will wait for user input, it's not present by default on WinXP, so executing it will only return an error message saying ""CHOICE" is not recognized bla bla bla"...

Here's a sample of batch menu on NT batch scripting:

@echo off
echo Choose:
echo [A] Option 1
echo [B] Option 2
echo.
:choice
SET /P C=[A,B]?
for %%? in (A B) do if /I "%C%"=="%%?" goto ok
goto choice
:ok
echo C=%C%

It's still a good idea to post your batch.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


Report Offensive Follow Up For Removal

Response Number 3
Name: Eric
Date: August 8, 2002 at 10:57:10 Pacific
Reply: (edit)

Here it is:
@echo off
goto menu

:menu
echo.
echo What would you like to do?
echo.
echo Choice
echo.
echo 1 Open Softphone
echo 2 Open Internet Explorer
echo 3 Open Mailout
echo 4 Open Lantern
echo 5 Open Notepad
echo 6 Open Netscape
echo 7 Quit
echo.

pause

choice /C:1234567 /n Your Choice:
if errorlevel 7 goto quit
if errorlevel 6 goto net
if errorlevel 5 goto note
if errorlevel 4 goto lan
if errorlevel 3 goto mail
if errorlevel 2 goto ie
if errorlevel 1 goto soft

:soft
start C:\Progra~1\
goto menu

:ie
start iexplore.exe http://www.google.ca/
goto menu

:mail
start h:\mailouts2.html
goto menu

:lan
start iexplore.exe http://
goto menu

:note
start notepad
goto menu

:net
start netscape -mail -P"netscape"
goto menu

:quit
exit
:end


Report Offensive Follow Up For Removal

Response Number 4
Name: Secret_Doom
Date: August 8, 2002 at 14:14:30 Pacific
Reply: (edit)

Are you sure that script pops up thw window and close immediately? The PAUSE command should prevent that...

Anyway, if CHOICE.COM is not present (and it's not present by default), the script won't work. Try this one:

===== BATCH SCRIPT BEGIN =====
@echo off
goto menu
:menu
echo.
echo What would you like to do?
echo.
echo Choice
echo.
echo 1 Open Softphone
echo 2 Open Internet Explorer
echo 3 Open Mailout
echo 4 Open Lantern
echo 5 Open Notepad
echo 6 Open Netscape
echo 7 Quit
echo.

:choice
set /P C=[1,2,3,4,5,6,7]?
if "%C%"=="7" goto quit
if "%C%"=="6" goto net
if "%C%"=="5" goto note
if "%C%"=="4" goto lan
if "%C%"=="3" goto mail
if "%C%"=="2" goto ie
if "%C%"=="1" goto soft
goto choice

:soft
start C:\Progra~1\
goto menu

:ie
start iexplore.exe http://www.google.ca/
goto menu

:mail
start h:\mailouts2.html
goto menu

:lan
start iexplore.exe http://
goto menu

:note
start notepad
goto menu

:net
start netscape -mail -P"netscape"
goto menu

:quit
exit
:end
===== BATCH SCRIPT END =====

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


Report Offensive Follow Up For Removal

Response Number 5
Name: Eric
Date: August 8, 2002 at 14:21:20 Pacific
Reply: (edit)

Thanks man, that really helps alot. Yeah, the pause command did stop it from closing, I put it there just for that because I wanted to see what the menu looked like, but if it wasn't there, it would close.

The only thing is, when i press a number, nothing happens???

Any way, thanks anyway, I'll try and figure it out, if you have any ideas, I'm all ears


Report Offensive Follow Up For Removal


Response Number 6
Name: Secret_Doom
Date: August 8, 2002 at 14:38:06 Pacific
Reply: (edit)

You gotta enter the number and press enter. Perhaps it would be good to inform user that such action is required.

If you need something more close to CHOICE.COM, see the following subject:
http://www.computing.net/dos/wwwboard/forum/11117.html

Nevertheless, I prefer this method which I posted here.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


Report Offensive Follow Up For Removal

Response Number 7
Name: Eric
Date: August 8, 2002 at 14:57:48 Pacific
Reply: (edit)

OK, I'll try that, thanks


Report Offensive Follow Up For Removal






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home








Do you have a Desktop Computer anymore?

No
Yes, but only at work
Yes, but its rarely used
Yes, and its a workhorse


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History




Data Recovery Software