VOGONS


First post, by swit

User metadata
Rank Newbie
Rank
Newbie

Hi,
I'm trying to create universal batch files for my games that will work in both windows and dos (inside dosbox). To run games from windows via batch files without adding DOSBox folder into each game I've decided to copy external batch file (AUTOEXEC.BAT) which is called after running dosbox. Sample batch file looks like this:

@echo off
cd ..\DOSBox
copy ..\GAMES\DUKE3D\!EXTRAS\AUTOEXEC.BAT /y
cls
dosbox -nogui -noconsole -conf dosbox.play.conf
exit

It works as intended in windows.

I'd like to use the same file also for dos. Here is my attempt in writing a proper batch file:

@echo off
tasklist /FI "IMAGENAME eq dosbox.exe" 2>NUL | find /I /N "dosbox.exe">NUL
if "%ERRORLEVEL%"=="0" GOTO:DOS
if "%ERRORLEVEL%"=="1" GOTO:WIN

:WIN
cd ..\DOSBox
copy ..\GAMES\DSJ210\!EXTRAS\AUTOEXEC.BAT /y
cls
dosbox -nogui -noconsole -conf dosbox.play.conf
exit
GOTO:EOF

:DOS
cd GAMES\DSJ210
cls
set DOS4G=quiet
DSJ.EXE
exit
GOTO:EOF

I will be grateful if someone could help me bugfixing it, because this one don't work neither in windows nor inside dosbox. Or maybe there is a simpler way to achieve it? The concept is simple: check if dosbox is running, if no - execute the normal commands like in the first batch; if yes - run the game.

Thanks in advance.

Reply 1 of 3, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

errorlevels should be tested from high to low

Water flows down the stream
How to ask questions the smart way!

Reply 2 of 3, by VileR

User metadata
Rank l33t
Rank
l33t

The most immediate problem is that TASKLIST obviously won't work from inside DOSBox, so you won't get your errorlevel. A better way to check would be:

if %COMSPEC% == C:\WINDOWS\system32\cmd.exe GOTO WIN

Or something like that, depends on your version of Windows. Then place the DOS section before :WIN.

[ WEB ] - [ BLOG ] - [ TUBE ] - [ CODE ]

Reply 3 of 3, by swit

User metadata
Rank Newbie
Rank
Newbie

Thanks! Now it's working like a charm.