Execute a command and wait

What’s the proper way to launch another app from within my Xojo app and have my Xojo app wait for the external program to finish?
The external program is not a command-line program but an actual .app (MacOS) or .exe (Windows)

The simple (in the sense of simplistic) answer is you need to use a timer to check with the priodicity of your choice whether the process carried out by the other application is done.

The difficult part may be having your xojo application know when the process has ended. If you need help with that you should provide details on what the external application is, can you modify it? what does it do? how would you know when it’s done?

HTH,

Julen

I see what you’re saying. Not quite so simple, so I’ll have to think about this.

Thank you for your reply!

[quote=471612:@Andy Broughton]What’s the proper way to launch another app from within my Xojo app and have my Xojo app wait for the external program to finish?
The external program is not a command-line program but an actual .app (MacOS) or .exe (Windows)[/quote]

how are you starting it in the first place ?
this may give a clue as to how you can wait for it to quit

I guess that’s my question - how SHOULD I start it?
Folderitem.launch is what I’m using currently. It runs the external program, but my Xojo app doesn’t wait for it to finish. Other commands I’ve done using shell and my Xojo app has waited for the command to complete. I’m not sure how Xojo knows that the shell command has completed, but I though maybe there was a simple way I could do that with an external app too. Probably not though…

folderitem.launch wont wait
its not supposed to and its mostly a good thing it doesnt :stuck_out_tongue:
except for when you DO want it to wait
then you resort to something else

on macOS a synchronous shell should work but you basically have to craft the right command to run at the shells “command line” its not actually the exact same as a Terminal window shell so be careful about that
but something like this will wait until Chess is quit


Dim s As New Shell

s.Execute("/Applications/Chess.app/Contents/MacOS/Chess")

break

note that you will not get to the break point until AFTER you quit chess

the path to the main executable in an app bundle is VERY consistent (always in /Contents/MacOS) but you could read it from the plist since it could have a different name than the bundle name :slight_smile:
in the Info.Plist its the key named CFBundleExecutable
for Chess this entry looks like

	<key>CFBundleExecutable</key>
	<string>Chess</string>

the SAME is NOT true in all cases on Windows
if you try


Dim s As New Shell

s.Execute("C:\\Program Files\\Microsoft Games\\Chess.exe")

break

you will find Chess starts and shortly after that you hit the break point chile chess is stil running :slight_smile:
I’m not sure how to make things behave properly on Windows as if you use START /WAIT basically a shell is started that runs the cmd and that completes and returns to your app promptly
I’m sure theres a declare or something that would work on Windows but the Windows Shell object is a very different beast from the macOS & Linux ones

Gotcha. Not so simple it seems, so I think I’ll save this issue for a later time.

Thanks, Norm!

@ might have a better answer on the Windows side but he’s been quite silent recently

Xojo apathy unfortunately, I’ll snap out of it some time

Dim s As New Shell s.ExecuteMode = shell.ExecuteModes.Synchronous 'just to make sure s.timeout = -1 'default is 2000, this was causing the skip s.Execute("notepad.exe") 's.Execute("start /b /wait notepad.exe") 'try this method if you have other issues Break

ah right the darned timeout !!!
always forget that darned thing is windows only :stuck_out_tongue:

Doesn’t this “hangs” the xojo application while it waits for the shell to complete?

For intercommunication between apps by same vendor I thought IPC sockets were the answer, and for launching other apps I thought capturing and monitoring the PID of the launched app was the proper way (easier said than done to be sure).

[quote=471735:@LangueR]Doesn’t this “hangs” the xojo application while it waits for the shell to complete?
[/quote]
It would - but thats what andy more or less asked for originally

[quote=471612:@Andy Broughton]What’s the proper way to launch another app from within my Xojo app and have my Xojo app wait for the external program to finish?
The external program is not a command-line program but an actual .app (MacOS) or .exe (Windows)[/quote]

Its not clear he is the author of the other app being launched

[quote=471737:@Norman Palardy]It would - but thats what andy more or less asked for originally[/quote]Yup!

[quote]Its not clear he is the author of the other app being launched[/quote]In this case, the external app is not my own.

Understood, but doing it the “shell” method makes your app fully unresponsive (in Windows). That is usually frowned upon. Not sure if that is really what you were going after. Just wanted to mention that.

What I would do in that case is

  • Hide the window
  • Call the synchronous shell
  • Show the window
    That way, the user perceives that the app “passed control” to the external app until it is complete.