Author Topic: Mame Roms not launching via .Bat file  (Read 16362 times)

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: Mame Roms not launching via .Bat file
« Reply #15 on: June 20, 2017, 05:41:09 PM »
I think that when the .bat file executes MAME, it does so from the RetroFE directory rather than the MAME directory, causing it to not find the mame.ini file, and thus not knowing where to find your roms. I'll need to investigate further. Perhaps it helps if you add a cd command to the MAME directory in your script before launching MAME.

Sent from my SM-G920F using Tapatalk


makaveeti

  • Newbie
  • *
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #16 on: June 20, 2017, 05:47:16 PM »
An alternative piece of code for doing the same thing is enclosed below however I get the same result (works from command line but not from retrofe)

D:

CD\emulators\retrofe080\emulators\mame

mame64.exe %1

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: Mame Roms not launching via .Bat file
« Reply #17 on: June 20, 2017, 06:18:02 PM »
I'll try running some tests tomorrow to see if I can figure it out. 😀

Sent from my SM-G920F using Tapatalk


Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: Mame Roms not launching via .Bat file
« Reply #18 on: June 20, 2017, 08:56:57 PM »
I can confirm that it doesn't work for me either. After a quick search I found that Windows has protections against launching batch files directly from C++ programs, so I'll investigate how to get around that. You say it works from EmulationStation though? I can check their code.

I thought I read that some people had managed to run shutdown scripts via .bat files; I wonder how they managed that then. Did you have any luck launching any .bat file from RetroFE so far?

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: Mame Roms not launching via .Bat file
« Reply #19 on: June 20, 2017, 09:08:55 PM »
It appears that RetroFE currently uses CreateProcess to launch a program, while EmulationStation uses _wsystem. CreateProcess has an interesting explanation:
"To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file."

So you could give it another try using cmd.exe as executable to let me know if you can solve it that way? If not, then I'll have a look at using _system or _wsystem in stead. I'm not sure why Emb chose CreateProcess, so I'm a bit hesitant to change things there out of fear of breaking other launchers.

See also https://ss64.com/nt/cmd.html
« Last Edit: June 20, 2017, 09:10:34 PM by Pieter Hulshoff »

JonahUK

  • Newbie
  • *
  • Posts: 35
  • Karma: +16/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #20 on: June 20, 2017, 09:33:50 PM »
I have used the following for bat files in the past: arguments = /C "%ITEM_FILEPATH%"

That launched my bat files fine, however, I have never tried launching multiple items though (ie, an ahk then mame + rom etc)

makaveeti

  • Newbie
  • *
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #21 on: June 20, 2017, 09:56:32 PM »
I have used the following for bat files in the past: arguments = /C "%ITEM_FILEPATH%"

That launched my bat files fine, however, I have never tried launching multiple items though (ie, an ahk then mame + rom etc)

Jonah,

Are you using a batch file for Mame? Can you tell me the code from your Mame launcher?

JonahUK

  • Newbie
  • *
  • Posts: 35
  • Karma: +16/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #22 on: June 20, 2017, 10:57:11 PM »
I have used the following for bat files in the past: arguments = /C "%ITEM_FILEPATH%"

That launched my bat files fine, however, I have never tried launching multiple items though (ie, an ahk then mame + rom etc)

Jonah,

Are you using a batch file for Mame? Can you tell me the code from your Mame launcher?

Unfotunately not anymore, no.
I use rocketlauncher for pretty much everything now.

An old example (iirc):

Code: [Select]
executable = ..\roms\pc\cmd.exe
arguments = /C "%ITEM_FILEPATH%"

cmd.exe copied to where the bat file resides but not sure if that was actually needed (again, iirc)

makaveeti

  • Newbie
  • *
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #23 on: June 21, 2017, 12:36:19 AM »
All,

I have managed to resolve the issue.

I tweaked the code slightly and copied cmd.exe to the mame emulator folder. Here is what my code looks like now. Hosting the cmd.exe file outside of the mame folder causes it to fail therefore the cmd.exe file must reside in the mame emulator folder.

I'm now able to run an AHK script with MAME :) Thanks to everyone who helped.

Launcher Code
executable = emulators\mame\cmd.exe
arguments = /C mame64.bat "%ITEM_NAME%"


Bat file Code
@echo off
pushd "D:\emulators\retrofe080\emulators\autohotkey"
start ahk.exe mame.ahk
pushd "D:\emulators\retrofe080\emulators\mame\"
mame64.exe %1

dustind900

  • Full Member
  • ***
  • Posts: 104
  • Karma: +9/-3
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #24 on: June 21, 2017, 02:58:00 AM »
Glad to see you got your .bat file working. Here is ahk code in case you are curious.

Code: [Select]
#Persistent

mameEXE := A_ScriptDir "\mame64.exe"    ;path to mame64.exe

RunWait, %mameEXE%,,, MAME_PID    ;RunWait will wait until the program finishes before continuing
Exitapp

Joy9::
KeyWait, Joy9, T2    ;wait 2 seconds for release key
if (ErrorLevel)    ;more than 2 sec have passed
Process, Close, %MAME_PID%    ;close MAME using the Process ID we got from the RunWait command
return

makaveeti

  • Newbie
  • *
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #25 on: June 21, 2017, 10:21:54 AM »
Glad to see you got your .bat file working. Here is ahk code in case you are curious.

Code: [Select]
#Persistent

mameEXE := A_ScriptDir "\mame64.exe"    ;path to mame64.exe

RunWait, %mameEXE%,,, MAME_PID    ;RunWait will wait until the program finishes before continuing
Exitapp

Joy9::
KeyWait, Joy9, T2    ;wait 2 seconds for release key
if (ErrorLevel)    ;more than 2 sec have passed
Process, Close, %MAME_PID%    ;close MAME using the Process ID we got from the RunWait command
return

Thanks dustind900. This will be very useful to me at some point. I'll test the code tonight. Just to clarify I'm assuming the script launches MAME auotmatically and continues running in the background waiting for me to hold joy9 for 2 seconds?

dustind900

  • Full Member
  • ***
  • Posts: 104
  • Karma: +9/-3
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #26 on: June 21, 2017, 10:52:13 AM »
Yes sir

Sent from my LG-H950 using Tapatalk


makaveeti

  • Newbie
  • *
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #27 on: June 21, 2017, 03:18:11 PM »
Yes sir

Sent from my LG-H950 using Tapatalk

In that case the above is certainly a sexy piece of code especially for an amateur coder like me :D I'll test tonight and feedback results.

makaveeti

  • Newbie
  • *
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #28 on: June 21, 2017, 05:43:21 PM »
Glad to see you got your .bat file working. Here is ahk code in case you are curious.

Code: [Select]
#Persistent

mameEXE := A_ScriptDir "\mame64.exe"    ;path to mame64.exe

RunWait, %mameEXE%,,, MAME_PID    ;RunWait will wait until the program finishes before continuing
Exitapp

Joy9::
KeyWait, Joy9, T2    ;wait 2 seconds for release key
if (ErrorLevel)    ;more than 2 sec have passed
Process, Close, %MAME_PID%    ;close MAME using the Process ID we got from the RunWait command
return

I've tried this in a standalone ahk exe so far and it executes mame just fine. Can you incorporate the passing of the rom file into the code too please? I think you mentioned earlier that its %1 or %1%.

Thanks.

dustind900

  • Full Member
  • ***
  • Posts: 104
  • Karma: +9/-3
    • View Profile
Re: Mame Roms not launching via .Bat file
« Reply #29 on: June 21, 2017, 06:11:36 PM »
Sorry about that.

Code: [Select]
#Persistent

/*
Info regarding ahk parameters
https://autohotkey.com/docs/Scripts.htm#cmd
 */

if 0 < 1    ;exit script if no parameters were passed
ExitApp

mameEXE := A_ScriptDir "\mame64.exe"    ;path to mame64.exe

RunWait, %mameEXE% %1%,,, MAME_PID    ;RunWait will wait until the program finishes before continuing
Exitapp

Joy9::
KeyWait, Joy9, T2    ;wait 2 seconds for release key
if (ErrorLevel)    ;more than 2 sec have passed
Process, Close, %MAME_PID%    ;close MAME using the Process ID we got from the RunWait command
return

Launcher
Code: [Select]
executable = emulators\MAME\mame.exe
arguments = %ITEM_NAME%    ; quotes aren't needed because there are no spaces in mame roms