Running a second executable within a primary app.
BlitzMax Forums/BlitzMax Programming/Running a second executable within a primary app.
| ||
I have a problem with the following code, when it is run from the IDE with debug enabled , the secondary application executes every time. There is a second snippet of code below which works 'intermittently'. i.e. sometimes the secondary app will run, sometimes it won't. The second piece of code is from a fully built executable. 'Attempt at running separate BMax executable within a BMax primary App: Local proc:TProcess = TProcess.Create(AppDir + "/breakrun.exe" , 0) Print "Looking for path:"+ AppDir + "/breakrun.exe" Print "Proc.status is currently:" + proc.Status() Delay 100' give process chance to start before checking its status DebugStop 'When debug mode enabled, this Must be allowing other app to run 'successfully 'Debug mode disabled, other app never runs ???+ While proc.Status() Delay 100 Wend Repeat Delay 20 Print "Proc.status is currently:"+proc.Status() count=count+1 Until count=100 'end jim b's advice DebugStop End' Not interested in running remainder of app if 'sub - app' never executes........ However, with debug mode disabled, the secondary app fails to initialise. It is a simple executable, merely a breakout clone. Output with debug disabled, proc status for second app is initially one, but quickly reverts to zero:- Looking for path:I:/BMaxLet/Spell_Go_BMax_5/breakrun.exe Proc.status is currently:1 Proc.status is currently:0 Have ended up omitting My poor code above (I'd appreciate it if someone can tell me why....), I have incorporated a slightly modified version of Jim's code to 'keep the secondary app' alive:- 'Attempt at running separate BMax executable within a BMax primary App: AppTitle$="Max App Launcher" ' variable to handle the launched application exec$=(AppDir+"\breakrun.exe") Local myproc:TProcess = TProcess.Create (exec$ , 0)' 'Local myproc:TProcess.Create(AppDir + "/breakrun.exe", 0 ) ' timer for updating the statusbar Local t:TTimer=CreateTimer(1) ' cross-platform executable extension filter ?Win32 Const ext$="Executable:exe" ?Linux Const ext$="" ?Mac Const ext$="" ? ' ===================================== ' main loop Repeat If AppRunning(myproc) Notify StripDir$(myproc.name$)+" still running, close this window to exit" Else f$=RequestFile$("Choose Executable",ext$) myproc=RunApp(f$) EndIf Exit 'End Select Forever End ' ===================================== ' launch an application Function RunApp:TProcess(app$) If app$="" Return Null Local proc:TProcess=TProcess.Create(app$,0) If Not Proc Notify "Failed to launch "+app$ Return proc End Function ' return true if app still running Function AppRunning(p:TProcess) If p<>Null If p.Status() Return True EndIf End Function ' update the status bar to reflect 'app running' status Function UpdateStatusBar(p:TProcess) If p=Null Print "App not running" Return EndIf If p.Status() Print "running" Else Print "App terminated" EndIf End Function 'end of Jim Browns sweet advice I have spent eeeoonns with lots of ee's trying to suus why... If anyone can shed any light I'd appreciate it - I am not using Max GUI, therefore I have not enabled the build GUI option. The second snippet of code works roughly 70 percent of the time... Haven't managed to figure why as yet..... Anyone able to provide a snippet of code to analyse why the secondary app bins out 20 to 30 percent o fthe time on execution. Regards, |
| ||
Anybody ??? Failing any ideas I might have to resort to incorporating my external app into the primary app... oh well. |
| ||
Easiest way would be building the second app in debug and test again. Then you will see why the second app dies. |
| ||
Thanks Dreamora, I've already taken the first painful steps of incorporating my external app into the primary one. It's for the best.... regards, |