Build Your Own Arcade Controls Forum

Main => Main Forum => Topic started by: Turnarcades on October 28, 2011, 03:21:59 pm

Title: Need a batch file to switch between two programs on exit from one
Post by: Turnarcades on October 28, 2011, 03:21:59 pm
Hi. Just a quickie I hope someone can help me with.

I'm setting up a system running two games only (both PC games with .exe extensions). Rather than having a front-end I want to set it up so it automatically boots into the first game, but when this program exits it automatically starts the second game and vice versa, so quitting one game always launches the other one.

I'm thinking a batch file will do the trick, setting the Windows shell to launch the .bat file on startup (as I've done with other projects), but I just need to know what to put in it to do this?
Title: Re: Need a batch file to switch between two programs on exit from one
Post by: codefenix on October 28, 2011, 06:38:07 pm
Code: [Select]
@echo off

:rungame1
GAME1.EXE

:rungame2
GAME2.EXE

goto rungame1

Title: Re: Need a batch file to switch between two programs on exit from one
Post by: JODY on October 28, 2011, 06:41:52 pm
There are many sites with good details on Windows batch scripting.  If you haven't find some, do a Google search.

You can use this as a basic framework.  I put in pauses instead of running programs and echo statements so you can see that it works.  Save the following into a .bat plain text file (e.g. use Notepad):

:first
echo first
pause
goto second

:second
echo second
pause
goto first

Title: Re: Need a batch file to switch between two programs on exit from one
Post by: Turnarcades on October 28, 2011, 07:55:46 pm
Thanks for the replies. So JODY, I just need to substitute the 'pause' entries with the exe file locations? I've created and used batch files before, it's just the actual logic of the entries that baffle me a bit.

Codefenix, yours is different, would this always switch back and forth between the games or just end after relaunching game 1?
Title: Re: Need a batch file to switch between two programs on exit from one
Post by: JODY on October 28, 2011, 09:00:48 pm
The first example runs the first game then upon exit would run the second.  After exiting the second, it loops back to the top and runs the first one again.

Mine had some unneeded lines.  The goto second isn't needed as it would fall into that part anyway.  Just wanted to show you some syntax.  Basically you can create sections and use goto statements to jump around. 
Title: Re: Need a batch file to switch between two programs on exit from one
Post by: Turnarcades on October 29, 2011, 06:50:21 am
Ok thanks, I'll give them a try! Reminds me of my days messing with Speccy basic.
Title: Re: Need a batch file to switch between two programs on exit from one
Post by: Thenasty on October 29, 2011, 10:37:11 am
@echo off
:Games
game1.exe
game2.exe
goto games



Title: Re: Need a batch file to switch between two programs on exit from one
Post by: eds1275 on October 31, 2011, 12:54:48 pm
!!!! When I was a kid, I was obsessed with programming. Unfortunately it was on a commodore 64. By the time I had gotten good enough at it to start designing my own stuff, it was obsolete. This doesn't look too far off from my commodore days! Maybe I should have kept up with it!