Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: wrybread on September 26, 2018, 08:04:32 PM

Title: Possible to execute some command when an emulator closes?
Post by: wrybread on September 26, 2018, 08:04:32 PM
I'm wondering if I can run some script when an emulator closes? In other words, if I start GameA from a Layout using EmulatorX, can a script run automatically when GameA exits?

I need to clean up a couple of extra windows that I'm running with my emulator, and trying to figure out a method.
Title: Re: Possible to execute some command when an emulator closes?
Post by: Favdeacon on September 26, 2018, 10:37:13 PM
Instead of starting the emulator directly from AM, you could start a script that starts the emulator. In that script, you could run whatever you want after the emulator. Just an idea I didn't test myself, yet.

edit: Alas, it's not that easy. AM seems to check when the emulator exits, so any command after it isn't executed. I tested it with a simple script that writes the time before and after mame into a file. It works when started directly, but if started from AM, the end time is omitted.

Which operating system do you use?

Title: Re: Possible to execute some command when an emulator closes?
Post by: wrybread on September 26, 2018, 10:55:58 PM
I'm on Linux. My "emulator" is a Python script that launches a few processes, and I'm trying to kill off the sub-processes.

I could do something like have a watcher script that kills the sub processes if the main process no longer exists, but I'm hoping to be a bit more tidy than that.
Title: Re: Possible to execute some command when an emulator closes?
Post by: Favdeacon on September 27, 2018, 11:33:53 AM
I am also on Linux, but I have next to no experience in scripting apart from some very basic bash.
Title: Re: Possible to execute some command when an emulator closes?
Post by: wrybread on September 27, 2018, 12:56:29 PM
I couldn't figure out a way to have Attract execute a command when a specific emulator closes so I just added some extra lines to my close action to tidy things up.

On a side note, using Python as a scripting language for Attract Mode emulators works great! And if you're looking to get more experience with Python, it's a fun project for it. I don't check this forum that often and I think email notification isn't working, but if you're having trouble with Python and Attract feel free to email me, my username at gmail.
Title: Re: Possible to execute some command when an emulator closes?
Post by: Favdeacon on September 28, 2018, 09:02:13 AM
Thank you for your kind offer, I will do so if the need arises.  ;D