Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Execute Executable & Executable Running - Anyone Using These Commands?

Author
Message
LightningSky
16
Years of Service
User Offline
Joined: 22nd Feb 2010
Location:
Posted: 7th Nov 2013 05:36
Trying to fire off some background processes that will handle various parts of my game. My main prog fires off the background prog just fine. I can switch between the two to make sure the background prog is running and doing it's thing (I have it printing stuff to the screen for debugging right now). Eventually the background prog(s) won't open any windows if I can help that.

Anyways, the problem is when I close the main prog it does not close the background prog. Starts it up fine, but doesn't close it.

Just prior to my main game loop I have:


And right after the main loop closes I have:


Am I just missing the boat on how these commands are to be used? As always I greatly appreciate your assistance.

- A man from nowhere, prophesized to fail, blazed beyond the brightest of them all.
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 7th Nov 2013 11:12
I believe those commands are for executing, stopping and checking other executables from your application.

Also, 'if-endif' after the main loop does nothing. Should be inside the main loop.

Regards Sph!nx
www.mental-image.net
GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 7th Nov 2013 15:33
I have a server application that opens a background window to handle the tasks that take a long time and I don't want the server app to stop processing messages to do. I open it just using "execute file", and here is how I stop it: (Requires Matrix)



My background application then uses IanMs "Set message callback" to capture the WM_CLOSE event and set a "closewindow" flag, and then ignore the WM_CLOSE message. This allows the background application to finish whatever task it is doing and then gracefully end after that.

LightningSky
16
Years of Service
User Offline
Joined: 22nd Feb 2010
Location:
Posted: 7th Nov 2013 21:13
@Sph!nx - I read somewhere in one of the forum posts that code after the loop would continue to process when the loop was completed. I haven't thoroughly tested this theory thought

@GIDustin - Thanks m8, I'll look into how I could use that.

- A man from nowhere, prophesized to fail, blazed beyond the brightest of them all.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 8th Nov 2013 09:13
Quote: "I read somewhere in one of the forum posts that code after the loop would continue to process when the loop was completed."

It will. I guess what Sph!inx meant is that the condition will only be checked once and skipped if not immediately true at the end (as opposed to it being checked over and over again if placed inside a loop). However, for that kind of check, the way you're doing it should be sufficient - if it isn't running at the termination of the program you can just leave it be

On a side note, I'm not too sure those functions actually work as intended.


"Why do programmers get Halloween and Christmas mixed up?"
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 8th Nov 2013 16:59 Edited at: 8th Nov 2013 17:02
It would seem to me that Sph!nx meant exactly what he said.

This does not work;


This works;
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 8th Nov 2013 18:48
That obviously doesn't work; what exits the loop?
If you press the escape key or the red cross in the corner of your window the default behaviour is to just instantly terminate the program (or well, it performs internal cleanup routines, but nothing more of your own code will be run). Thus it won't ever reach the if branch.
Removing the loop, it will still most likely fail because the notepad instance haven't had time to open properly before your check, thus the executable running function will return false (which can be a bit confusing, but yes, it will actually report false for a brief moment before the application has been started up).


"Why do programmers get Halloween and Christmas mixed up?"
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 8th Nov 2013 19:10 Edited at: 8th Nov 2013 19:16
Quote: "what exits the loop?"


I am checking the escapekey in the loop. This is what exits the program.

Quote: "Removing the loop, it will still most likely fail because the notepad instance haven't had time to open properly before your check, thus the executable running function will return false (which can be a bit confusing, but yes, it will actually report false for a brief moment before the application has been started up)."


In the first snippet; it doesn’t matter how long you wait in the loop. I would think executable running should register, if that is the case.

If you press the red cross, the program terminates right then, unless your using a plug-in that will trap that condition.

Edit: I have found no evidence that program execution continues after using the escape key to exit a do/loop. If you have code that demonstrates this, that would be great.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 8th Nov 2013 20:39
A do-loop is only broken by using the exit keyword (or returning from a function / jumping to a label if you're in a situation where such is possible).
Pressing the escape key without previously calling disable escapekey will cause it to terminate your application. If you disable it, pressing it will do nothing unless you tell it to, for example like so:


Quote: "I am checking the escapekey in the loop. This is what exits the program."

I was talking about your first snippet, not the second


This works as intended:

If you remove the call to sleep, the DBP program will finish before notepad has started, thus it won't be stopped.
After checking, I was incorrect in assuming executable running would return false at this time; it doesn't. What seems to be happening is that stop executable has no effect if it's called before the executable has started up properly.


"Why do programmers get Halloween and Christmas mixed up?"
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 8th Nov 2013 20:56 Edited at: 8th Nov 2013 20:57
I was wondering if maybe I misunderstood your post. Seems that we are on the same page, thanks. Anyway this snippet uses BlueGUI to trap the close button.

LightningSky
16
Years of Service
User Offline
Joined: 22nd Feb 2010
Location:
Posted: 9th Nov 2013 02:10
Well, it would appear that even if I could get the main app to kill the background apps, there is a hole in my theory in the sense that if the user choses to run the game in "windows" mode, they could click the close button and kill the main app without further code firing to close the background progs.

I'm going to write into the background processes to be looking for "alive" records in one of the dark data files. If the main prog keeps posting alive records then the back ground progs would continue to do their thing. Once those records stop being generated (the main prog was closed for some reason) they would exit as well.

I have BlueGUI, I'll play around with that option first, thanks WickedX for the sample code on that.

Thank you everyone for ironing out the function of these commands. Much appreciated.

- A man from nowhere, prophesized to fail, blazed beyond the brightest of them all.

Login to post a reply

Server time is: 2026-07-07 01:53:00
Your offset time is: 2026-07-07 01:53:00