Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Running an external executable

What's the syntax I would use to run an external .exe file? For a project of mine, there's a launcher program that takes you into the game and I want to put in a command in the game to return to the launcher. Additionally, is there a way to automatically call this command when the game is closed?

Any help is appreciated.
 
Well, I made a MAME launcher for RMXP a while back, and the syntax was quite simple. I used the following code to launch MAME from a subfolder (named MAME, of course), as though I had double-clicked it, and then close the game.

Code:
system("START MAME\\mame.exe")

exit

Please note that in that string, after the line calling the executable, you can actually add calls like you would in the command prompt. I used these to launch the game I wanted, with the settings I preferred. (For example, I used it to launch an FPS so that it would track the mouse as the gun, instead of using the arrow keys) The system command actually executes code as though it was a .bat file (mostly). The exit line actually served to close the game, as it would imply.
 
Glitchfinder":2a4k2lv2 said:
Well, I made a MAME launcher for RMXP a while back, and the syntax was quite simple. I used the following code to launch MAME from a subfolder (named MAME, of course), as though I had double-clicked it, and then close the game.

Code:
system("START MAME\\mame.exe")

exit

Please note that in that string, after the line calling the executable, you can actually add calls like you would in the command prompt. I used these to launch the game I wanted, with the settings I preferred. (For example, I used it to launch an FPS so that it would track the mouse as the gun, instead of using the arrow keys) The system command actually executes code as though it was a .bat file (mostly). The exit line actually served to close the game, as it would imply.
Thanks a ton! Now, is there a way to make it automatically run that code when the game is closed?

EDIT: Another problem is that since the new program to run becomes the active window, the RMXP game doesn't actually quit unless you make it active again.
 
well basically the ruby interpreter can't close until the last expression has completed...
And as the other program is running, the system command is still running until you close that other program.
 
trebor777":uvi0h276 said:
well basically the ruby interpreter can't close until the last expression has completed...
And as the other program is running, the system command is still running until you close that other program.
Calling system inside a thread, allows the ruby interpreter to close even if the system call hasn't finished.
Code:
Thread.new {system('calc.exe')}

exit
 
vgvgf":1bpbmgl7 said:
trebor777":1bpbmgl7 said:
well basically the ruby interpreter can't close until the last expression has completed...
And as the other program is running, the system command is still running until you close that other program.
Calling system inside a thread, allows the ruby interpreter to close even if the system call hasn't finished.
Code:
Thread.new {system('calc.exe')}

exit
Thanks a ton! Now, the only issue I need help with is making something happen when the player clicks the X button. How would that be accomplished?
 
Sailerius":3iryykva said:
Thanks a ton! Now, the only issue I need help with is making something happen when the player clicks the X button. How would that be accomplished?
The Game Player X button? Or the new started application?

If it is the RM Game Player, just add in main a "ensure", for example in RMVX main:
Code:
begin

  Graphics.freeze

  $scene = Scene_Title.new

  $scene.main while $scene != nil

  Graphics.transition(30)

rescue Errno::ENOENT

  filename = $!.message.sub("No such file or directory - ", "")

  print("Unable to find file #{filename}.")

ensure

  p true

end
When the user tries to close the program, "p true" will still be called.
 

e

Sponsor

I might be wrong, but I think the only possible way of doing this is using your launcher program. If it does launch the game, then it knows the process, the process ID, etc., and can potentially hook itself to the game window to intercept messages (more on windows hooks: http://msdn.microsoft.com/en-us/library ... 59(v=VS.85).aspx)

Otherwise, I suppose it might be doable in Ruby using a complicated series of Win32API calls, but I'm unsure if that's even possible.
 
Hooks are NOT a good idea. They are effectively keyloggers, and they will also slow down the system if not handled properly. There's a reason I'm working on a .dll file for an alternative version of my input scripts, instead of using hooks. (Well, several reasons, but these are the most pertinent of them)
 

e

Sponsor

Then propose an alternative solution to his problem; as far as I know, there's no other way to capture Window messages otherwise. As for them being keyloggers, erm, keyloggers use them, certainly, but they're tools; it'd be like saying knives are murderers.
 
vgvgf":3of636co said:
Sailerius":3of636co said:
Thanks a ton! Now, the only issue I need help with is making something happen when the player clicks the X button. How would that be accomplished?
The Game Player X button? Or the new started application?

If it is the RM Game Player, just add in main a "ensure", for example in RMVX main:
Code:
begin

  Graphics.freeze

  $scene = Scene_Title.new

  $scene.main while $scene != nil

  Graphics.transition(30)

rescue Errno::ENOENT

  filename = $!.message.sub("No such file or directory - ", "")

  print("Unable to find file #{filename}.")

ensure

  p true

end
When the user tries to close the program, "p true" will still be called.
Yes, thank you! That's exactly what I was looking for. I can't believe it was that simple.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top