VOGONS

Common searches


Creating a batch file with more than 10 options

Topic actions

  • This topic is locked. You cannot reply or edit posts.

First post, by Lemur21

User metadata
Rank Newbie
Rank
Newbie

So - I posted this about a week ago on Reddit (posting the link here so people see what I was asking).

https://www.reddit.com/r/Batch/comments/azlir … _nonprogrammer/

It looks like most of what was suggested there (including set /p) isn't compatible with DosBox. After a bunch of frustrating attempts, I had the bright idea to launch the .bat file *outside* of DosBox, launching DosBox from within the batch file (compared to launching the batch file from within DosBox) and then, continuing from there. So far, my trial and error has resulted in a lot of error.

Any ideas???

Reply 1 of 25, by retardware

User metadata
Rank Oldbie
Rank
Oldbie

If that does not work within DosBox it should be considered a bug in DosBox, as this would mean DosBox being incompatible.

Looks like you are running a Windows system and calling DosBox in the host systems' batch file. This does not pass the environment.

Reply 4 of 25, by Lemur21

User metadata
Rank Newbie
Rank
Newbie

Here is the code I have now - and it's definitely not correct:

@echo off

:top
cls

echo Please choose an option
echo.
echo 1.College Basketball
echo 2.Baseball
echo 3.Football
echo 4.Pro Basketball
echo 5.Hockey
echo 6.Boxing
echo 7.Diamond Mind Baseball
echo 8.College Basketball
echo 9.Baseball
echo 10.Football
echo 11.Pro Basketball
echo 12.Hockey
echo 13.Boxing
echo 14.Diamond Mind Baseball
echo 15.Dos Prompt
echo 16.Exit
echo.
echo Your choice?

set /p choice=">"

if %choice%==1 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 1
if %choice%==2 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 2
if %choice%==3 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 3
if %choice%==4 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 4
if %choice%==5 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 5
if %choice%==6 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 6
if %choice%==7 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 7
if %choice%==8 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 8
if %choice%==9 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 9
if %choice%==10 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 10
if %choice%==11 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 11
if %choice%==12 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 12
if %choice%==13 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 13
if %choice%==14 cd \Program Files (x86)\DosBox_MB6 & call "dosbox.exe" & goto 14
if %choice%==15 cls & goto none
if %choice%==16 exit

:1
cd \LHCBask & call "hello.exe"

:2
cd \LHBase & call "hello.exe"

:3
cd \LHFoot & call "hello.exe"

:4
cd \LHBask & call "hello.exe"

:5
cd \LHHock & call "hello.exe"

:6
cd \TKOBOX & call "hello.exe"

:7
cd \DMB7 & call "baseball.exe"

:8
cd \LHCBask & call "hello.exe"

:9
cd \LHBase & call "hello.exe"

:10
cd \LHFoot & call "hello.exe"

:11
cd \LHBask & call "hello.exe"

:12
cd \LHHock & call "hello.exe"

:13
cd \TKOBOX & call "hello.exe"

:14
cd \DMB7 & call "baseball.exe"

echo Option not found. Please select a valid option
pause
goto top

Reply 5 of 25, by Roger Wilco

User metadata
Rank Newbie
Rank
Newbie

I wrote a lot of batch files as well and set/p works with Freedos, I just checked. Download it and start a shell in Dosbox by typing command in the Freedos folder.

@echo off

echo Please choose an option
echo.
echo 1.
echo 2.
echo 3.
echo.

set /p choice=Your choice?

if '%choice%'=='1' goto 1
if '%choice%'=='2' goto 2
if '%choice%'=='3' goto 3


:1
echo 1
goto end

:2
echo 2
goto end

:3
echo 3
goto end

:end

Allthough you might have more fun with a menu like this one:
New MS-DOS Games Launcher / Menu System App

Reply 6 of 25, by Lemur21

User metadata
Rank Newbie
Rank
Newbie

But - if I start it in freedos, and then launch DosBox, will that terminate the set /p? I was assuming - since i'm starting the .bat file in a cmd prompt (i.e., it's not part of the DosBox config file) that it would avoid the DosBox termination.

I *do* like the menu you created there; but I know (1) I need DosBox to run these effectively; (2) I don't have a spare Dox machine; and (3) i need to be able to print (which I was able to get set up in DosBox (surprisingly - that was *easier* than the batch file!) 😀

Reply 9 of 25, by Roger Wilco

User metadata
Rank Newbie
Rank
Newbie

Its simple. Download Freedos. Mount the folder containing Freedos, so that you can see it in Dosbox. Start the command.com of Freedos in Dosbox by typing command in the Freedos folder.

You will see "FreeCom version 0.84.." and so on written there.
That's your new freedos shell. All is the same as usual, but set /p (and others) is going to be handled by Freedos from that point on, not by Dosbox.
In that shell, you can start your bat files, with set/p working.

You have to do this every time you restart Dosbox, so you might want to write that into the dosbox configuration file, at the very end, below [autoexec].
Everything thats written there is started automatically, when Dosbox launches.

Thats about it!

Reply 12 of 25, by cyclone3d

User metadata
Rank l33t++
Rank
l33t++

Looks to me like you are doing the menu completely wrong. You don't need IF statements. Put all commands in the code blocks for the different options.

Back in the day I had huge menus in Config.sys and Autoexec.bat and I never used IF statements.

See here for an example:
https://www.dostips.com/DtTipsMenu.php

Yamaha modified setupds and drivers
Yamaha XG repository
YMF7x4 Guide
Aopen AW744L II SB-LINK

Reply 13 of 25, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

DOSBox's built-in shell does not support "SET /P" because MS-DOS 5 and 6 do not support it. Instead, use the CHOICE command and IF ERRORLEVEL structures to implement batch menus. It's not an optimal example, but see this thread: [SOLVED] Batch scripting - Help with choice command

Reply 14 of 25, by retardware

User metadata
Rank Oldbie
Rank
Oldbie
ripsaw8080 wrote:

DOSBox's built-in shell does not support "SET /P" because MS-DOS 5 and 6 do not support it.

Does this mean that "set comspec=c:...\command.com /p /e:xxx" has no effect anymore in newer DOS?

Reply 15 of 25, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author
retardware wrote:
ripsaw8080 wrote:

DOSBox's built-in shell does not support "SET /P" because MS-DOS 5 and 6 do not support it.

Does this mean that "set comspec=c:...\command.com /p /e:xxx" has no effect anymore in newer DOS?

No, because in that case the /P is a parameter of COMMAND.COM, not the SET command.

Reply 16 of 25, by dr_st

User metadata
Rank l33t
Rank
l33t

Threads like this that start with some rather unusual request, based on a set of unverified and undisclosed assumptions, and with the OP replying with "you lost me" to every suggestion tick me off just a bit.

Lemur21, Maybe you should start with explaining - what the hell are you trying to achieve? Yes, I understand - you want a batch file with more than 10 options, but for what purpose?

Oh, geez, whatever. It's pretty obvious what you're about to do, you are just going a very roundabout way about it.

Here's the simple solution:

You want a batch file with more than 10 options? Fine, use choice /c0123456789abcdefghijklmnopqrstuvwxyz and check for errorlevels 36-1. That is ought to be enough, since it gives 36 choices, which is more than fit on a 80x25 standard DOS screen. And yes, it works in DOSBox.

Still not enough, or you have a weird aversion to using letters in batch files? Well, tough. Use a system of nested choices (either in the same batch file or from other batch files called from the main batch file). Anything else (like typing a 2-digit number and pressing Enter) cannot be achieved via the primitive batch file / DOS command line interpreter and you'll need to use some third-party utilities to get that behavior (like FreeDOS command interpreter).

https://cloakedthargoid.wordpress.com/ - Random content on hardware, software, games and toys

Reply 18 of 25, by dr_st

User metadata
Rank l33t
Rank
l33t

Yeah, that bothers me as well. 😉 As you may have noticed, I edited my rant multiple times to get it to the final form, which I think is fair and not too stuck up.

The CHOICE is the obvious solution, and it is in fact what OP had from the very beginning; I just wanted to emphasize that CHOICE is not limited to numbers so you can have more than 9 options- something which apparently newbies don't think about, and looks like the OP was stuck that that very point.

https://cloakedthargoid.wordpress.com/ - Random content on hardware, software, games and toys

Reply 19 of 25, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Ah, yes, the alphanumeric thing is perhaps not obvious and worth clarifying. 😉

Actually, since ERRORLEVEL goes up to 255, one could make a simple program that takes a numeric input and sets the error level to that. Maybe more choices than one can really use, though.