How to start another exe..?

BlitzMax Forums/BlitzMax Beginners Area/How to start another exe..?

xMicky(Posted 2006) [#1]
From the forums I learned how to start another .exe like this:
1) Local process:TProcess =TProcess.create("C:\WINDOWS\system32\calc.exe",0)
and like this:
2) system_ "notepad"

But #1 kills the called process if the calling .exe is terminated and #2 makes the calling application waiting (freezing it) until the called application is finished.
What I wish to do is to call another program and than to end the calling program without an effect to the called program, it should run furtherly.
Is there a way to achieve this ?


Beaker(Posted 2006) [#2]
Try this:
Extern "win32"
Function ShellExecuteA(hwnd,op$z,file$z,params$z,dir$z,showcmd)
End Extern

ShellExecuteA(0,"open","calc.exe","","",SW_SHOWNORMAL)

http://support.microsoft.com/?kbid=238245#kb3


Dreamora(Posted 2006) [#3]
A process is always ended if the exe is ended as the exe IS the process. What would a running process of a not further existing app exactly do? Look nice? :-)
Might I ask what the actual problem with this behavior is?
You can ask the process if it is still running if this is your problem, so you can restart it or react to its "ending".

There isn't anything that you can do to make an app "run forever" which is the only way to have a process doing the same (until you manually kill it), at least no legal way, because an app and thus its process can be killed through the process manager.


xMicky(Posted 2006) [#4]
Thanks for the reply, Beakers code seems to be the solution for my problem.

I asked because I'm experiencing some vague ideas of a way to write a game in components the user may put together depending on his flavour (like buying a car nowadays where you can choose nearly each detail after your wishes). The choosen .exes then can call each other in the progressing game, and therefore I just need a technique to make this chain flow.


Dreamora(Posted 2006) [#5]
Hmm ... But this still needs a main application that actually controls / starts them (I assume you use UDP as communication layer between the apps? Pipe is nice but is a "on hold" communcation), which is perhaps why I don't see why the TProcess approach won't work.
The other app won't finish until it codes makes it to do so (ie you wanted it codewise to do so) or you finish the process in the "main application".
The user can be gotten out of way if you own MaxGUI and create the window through with window hidden flag ;-)

But a nice idea in general :)
I use a similar approach so far to do virtual multi threading by spawning different sub applications I can use to do calculations asyncronous and that communicate to each other through UDP. This sadly has its restrictions, but for basic things it works quite good.


FlameDuck(Posted 2006) [#6]
The choosen .exes then can call each other in the progressing game, and therefore I just need a technique to make this chain flow.
Do what UFO: Enemy unknown did. Run a script.


SebHoll(Posted 2006) [#7]
If you checked back a week or so back, someone else was asking a similar question and the answer is to use OpenURL$ on the EXE! It's cross platform and I think the Windows version performs the ShellExecute command intenally when this function is called.


AlexO(Posted 2008) [#8]
Oi, been searching for hours on this. Has anyone come across a way to launch an app from within blitzmax with command line arguments? OpenURL() doesn't support command line arguments. I want the app to simply launch one other app and then 'end'. Reason behind this is I'm writing a self-updating exe. Currently I'm just saving out 'arguments' to a temp file for the newly launched app to read, but was hoping for a cleaner solution.


Otus(Posted 2008) [#9]
You could run a script file (eg. .bat on Windows) with system_. You would need different scripts on different platforms, though. On Windows this could be something like:

Blitz program:
system_ "StartProgram.bat " + opt$


StartProgram.bat:
START "Program.exe" %1



AlexO(Posted 2008) [#10]
O wow, system_ "some stuff" seems to support commandline arguments. Does calling system_ work on Mac also?

Edit: doh but this seems to be a blocking call.