0

I think I have what I want (described below), thank you so much again, but please two more options... When I want to add in sub menu two next options for example "B" like go on Begin and "E" like Exit. It will be like:

Hello I am Zedd, please choose one app bellow:

  1. Notepad
  2. Calc
  3. Other

When I touch "3" like other I will get next menu:

  1. FFox
  2. IE
  3. or B. Go Back
  4. or E. Exit

How can I do this? And can I use just number 0-9 or I can use also 10,11 etc.?

Examople of code maybe like this?

@echo off  
:begin  
echo.  
echo Hello, I'm Zedd...  
echo.  
echo Choose:
echo.  
echo 1. Notepad  
echo 2. Calc  
echo 3. Other  
echo.  
choice /c 123  
if %errorlevel%==1 goto :Notepad  
if %errorlevel%==2 goto :Calc 
if %errorlevel%==3 goto :Other

:Notepad  
start notepad.exe  
goto :eof 

:Calc  
start calc.exe  
goto :eof 

:Other  
echo.  
echo Choose:  
echo.  
echo 1. FFox  
echo 2. IE  
echo 3 or B. Back
echo 4 or E. Exit  
echo.  
choice /c 1234(maybe 12be if I can use also b and e, or I can use 3,4... is possible here use 10,11,12 etc.?)    
if %errorlevel%==1 "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"  
if %errorlevel%==2 "C:\Program Files\Internet Explorer\iexplore.exe"  
if %errorlevel%==3 goto :begin?  
if %errorlevel%==4 exit?  
goto :other (I want to stay in other for choosing next apps but I want to be able to go back or exit)

Also, can I do it with note, so when I choose FFox there will be message "You choosed FFox" etc.?

Hope I described it clearly, if you can help me, I will be happy, thank you!


Could you please advise me on how to write commands in CMD using a batch file that would include different options and actions?

I've researched a nice description of the functions I can use, but I'm not able to put together them functionally.

Here's an example of the output message that I want when my batch file runs on Windows:

I need to do batch, for example "test.bat"

I think this is the easiest way. In this batch I want to have some text and some choices. For example bellow:

Hello, I am Zedd, here is few options for you, please choose one. 

1. Run notepad.exe 
2. Other apps

After entering number 1, Notepad is opened. After entering number 2, more options should be displayed:

1. Firefox
2. More informations
   etc.

I need to run this batch file on Windows.

What is best way how to do this?

It can be full-screen or just within a window.

Also I need open apps or pictures, etc.

Zedd
  • 1
  • 3
  • Is it _actual_ MS-DOS or just the cmd window? Are you literally running MS-DOS 6 (or whatever version is on the legacy system you are using)? Because there is actually a **huge** difference between the two and some commands for one won't work on the other. – SomethingDark Aug 13 '15 at 18:08
  • the question states "my batch file runs on Windows". – Stephan Aug 13 '15 at 18:12
  • Just cmd windows, which possibilities are here? Yes, you are right, so sorry about this, I'll correct it if possible... – Zedd Aug 14 '15 at 07:02
  • fullscreen? not with batch. Open program or App? yes (for example just `notepad.exe`). Using options? yes - if the program or app supports them. Hard to help you, if you don't state a specific problem. – Stephan Aug 14 '15 at 08:41
  • Ok, so all what I need is possible, but I don't know how to do it... so I try to describe it again. I need to do batch, for example "test.bat" <- I think this is the eaisiest way. In this bath I want to have some text and some choices... for basic example: Hello, I am Zedd, here is few options for you, please choose one. 1. Run notepad.exe 2. Other apps After touch number 1 is opened notepad. After touch number 2 we can see next options 1. Firefox 2. More informations Etc. etc., I hope now is more clear what I need. Sorry again about this and thank you! – Zedd Aug 14 '15 at 10:32
  • yes, save it as "test.bat" and run it. Edited my answer to include a second level of choices. – Stephan Aug 14 '15 at 12:04
  • possible duplicate of [Multiple choices menu on batch file?](http://stackoverflow.com/questions/14529246/multiple-choices-menu-on-batch-file) – Mofi Aug 15 '15 at 12:44
  • I think this was solved, now I have few more questions, can you help me please? Thank you so much! – Zedd Sep 02 '15 at 09:02
  • @Zedd see my edited answer (in the future please don't change your question, ask a new question instead; maybe with a reference to this one) – Stephan Sep 02 '15 at 14:25
  • @Stephan thank you so much for your BIG help, I really appreciate it. I understand and next time will do new question, sorry for that. But now please finish this, I asked one more thing in comment bellow, under you answer. – Zedd Sep 03 '15 at 11:55

2 Answers2

1

(Edited to show the usage of a second level of choices)

just a combination of echo and choice commands:

@echo off
:begin
echo Hello, I am Zedd, here is few options for you, please choose one. 
echo 1. Run notepad.exe 
echo 2. Other apps
choice /c 12
if %errorlevel%==1 goto :notepad
if %errorlevel%==2 goto :other    
:notepad
echo you choosed Notepad.
start notepad.exe
goto :eof

:other
echo 1. Mozilla Firefox
echo 2. Microsoft Internet Explorer
echo 3. MyBatchFile
echo B. back to main menue
echo E. exit
choice /c 123B
if %errorlevel%==1 "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
if %errorlevel%==2 "C:\Program Files\Internet Explorer\iexplore.exe"
if %errorlevel%==3 (
  echo you choosed MyBatchFile
  call "c:\test\mybatch.bat"
  goto :begin
)
if %errorlevel%==4 (
  echo you entered "B" to go back to main menue
  goto :begin
)
if %errorlevel%==5 (
  echo bye bye...
  exit /b
)
goto :other

You can add the /n parameter to choice to supress [1,2]?

EDIT 02-sep (please don't change your question, this may invalidate already existing answers; ask a new question instead, referencing this old question)

"How can I do this? And can I use just number 0-9 or I can use also 10,11 etc.?"

No. choice reacts on keypresses, not on input strings, so only single numbers or letters. Although 3 or B. Back is possible: choice /c 123b4e will return errorlevel 1 for 1, 2 for 2, 3 for 3, 4 for b or B, 5 for 4, 6 for e or E. (read choice /? for details). Then

...
if %errorlevel%==3 goto :back   REM this was a "3"
if %errorlevel%==4 goto :back   REM this was a "B"
...

"Also, can I do it with note, so when I choose FFox there will be message "You choosed FFox" etc.?"

Yes. Just add an echo after each label (see example above with the :notepad label.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • 1
    If he's literally running MS-DOS, there is no choice option. (Admittedly, he's likely not, but there's still room for ambiguity right now.) – SomethingDark Aug 13 '15 at 18:09
  • Thank you for answer, its near, but still not what I need to do. – Zedd Aug 14 '15 at 07:04
  • so, what do you need? Please [edit](http://stackoverflow.com/posts/31990450/edit) your question – Stephan Aug 14 '15 at 07:33
  • Thank you so much for edition Stephan, if I add @ on begin, its hide "ways" and other tags, not it lookis like it is what I was looking for. Thank you again, If I will have some issues, I ask you again, if possible. – Zedd Aug 14 '15 at 13:51
  • just add `@echo off` as the first line. That will suppress command repetition for all lines. – Stephan Aug 14 '15 at 14:27
  • Stephan, thank you again, I still have problem with "Exit" and "go to Begin", its not working for me. Also I need to add "message" to %errorlevel% if possible. My example 'echo. choice /c 12be if %errorlevel%==1 \\t1\t1\t.bat echo you chosed t1 if %errorlevel%==2 \\t2\t2\t2.bat echo you chosed t2 if %errorlevel%==b goto begin if %errorlevel%==e exit goto :Other' I need to stay in selection for "other" because I choose to run 1 after 2 and after I can go back or exit, so its why is on end "goto :Other", but how can I do Exit/Close or goto :begin if this is on end? Also how about echo msg here? – Zedd Sep 03 '15 at 12:02
  • I implemented your requests (in different ways - not a good programming behaviour - to show you different possibilities). Keep in mind: if you just start another batchfile with `c:\t1\t1\t1.bat`, it will never return. Use `call` to continue after `t1` is finished.. – Stephan Sep 03 '15 at 13:30
  • @Stephan, thank you so much for all, now is all working how I need, you are really good guy, big up for you! – Zedd Sep 04 '15 at 11:54
  • the best "big up" would be to accept the answer. This will also tell everyone, this question has been solved. – Stephan Sep 04 '15 at 12:06
0

Yes, it could be possible to do that in plain batch commands. I would suggest, though, use a language like C++ or C, to do that...but if you must use batch, here are a lot of commands that you can play with.

Joel
  • 1,805
  • 1
  • 22
  • 22
  • 1
    You would be surprised, [what's possible](http://www.dostips.com/forum/viewtopic.php?f=3&t=4741), using plain batch... – Stephan Aug 13 '15 at 17:24
  • Thank you all for your time and help. I checked commands and md-dos examples, but I still can't find what I want. Also, I need to see it on example, because it is lot of years when I did similar thing at last and now I am lost. Thank you for understanding. – Zedd Aug 14 '15 at 07:06