VOGONS

Common searches


First post, by paulcmnt

User metadata
Rank Newbie
Rank
Newbie

I'm trying to write a batch script to open an application through DOSBox. How can I pass the arguments that the script receive to DOSBox, so it can further pass those arguments to the application I want to open? My script currently has only one line:

start DOSBox\DOSBox.exe BIN\TASM.EXE -noconsole

Reply 1 of 2, by Asterisk

User metadata
Rank Newbie
Rank
Newbie

The standard way of passing arguments through batch files (either DOS .bat or Windows .cmd) is to use the variables that the OS automatically assigns to all parameters after the command, beginning at %1. For example, if I had a batch file called foo.bat, and ran it with parameters after the command...

C:>foo.bat bar baz qux 

...then within the batch file, %1 would contain the value bar, %2 would contain the value "baz", and %3 would contain the value "qux".

So, if I wanted to write a batch file that launched DOSBox with, say, a specified configuration file, I could write the following batch file:

@echo off
dosbox.exe -conf %1

If this batch file were saved as "dblaunch.cmd", I could invoke it with the command "dblaunch foo.conf", and the value "foo.conf" would take the place of the variable %1 in the script.

You can do a lot more than this, including defining your own parameter flags and using a loop to parse arguments in order to make it less dependent on parameter order (heavy use of set, shift, and goto commands would be necessary, as would familiarity with batch subroutines). You could also use if to check the validity of parameters and verify that specified file paths actually exist.

For a good reference to Windows command scripting, I recommend The CMD pages at SS64.com: http://ss64.com/nt/.

Reply 2 of 2, by blinkingblythe

User metadata
Rank Newbie
Rank
Newbie
paulcmnt wrote:
I'm trying to write a batch script to open an application through DOSBox. How can I pass the arguments that the script receive t […]
Show full quote

I'm trying to write a batch script to open an application through DOSBox. How can I pass the arguments that the script receive to DOSBox, so it can further pass those arguments to the application I want to open? My script currently has only one line:

start DOSBox\DOSBox.exe BIN\TASM.EXE -noconsole

Here is one way of doing it:

copy the dosbox.conf file to startup.con

add this to the autoexec area (at the end) of startup.con

rem replace "dosgames" with whatever folder your dos games are in
mount c c:\dosgames
mount d c:\bat
c:
call d:\begin.bat
exit

Make a a folder in c:\ called bat

next, write this batch file (call it db.bat)

@echo off
echo cd %1>c:\bat\begin.bat
echo. %2 %3 %4 %5 %6 %7 %8 %9>>c:\bat\begin.bat
:: replace next line to whatever folder dosbox is in.
cd \dosbox
dosbox -conf startup.con

Here's the usage:

db (folder name of dos game) (executable name and parameters)