Trying to run the below code, and it starts the process but then the app hangs until i terminate it via a kill command in the console. What am I doing wrong?
If TargetLinux Then
Var sh as New Shell
sh.ExecuteMode = Shell.ExecuteModes.Synchronous
sh.Execute("/usr/bin/udiskie", " &")
End If
The ampersand parameter tells bash to run the command in the background and continue. I have tried it as part of the command line, and also as a parameter above. No change.
The code compiles, runs, then hangs. I kill the process ID for udiskie and my app comes back to life.
Synchronous
(Default) The shell executes its command and returns the result in the Result property when the script has finished running. Synchronous shells block the main UI thread, even when they are in a thread themselves. For long-running shell processes, use one of the other shell modes instead.
I agree that the " &" should background the udiskie task, and the shell should end. Maybe there’s a bug on Linux? Perhaps you should try Asynchronous instead?
Edit to add:
Could the “sh” object going out of scope be an issue? Maybe try making the “sh” object a global variable and see if that helps?
Shell using Synchronous mode keeps waiting for the process to end. Since the process is still running, it hasn’t ended and Xojo still waits. You can find details on the specific mode behaviors in the Xojo documentation: Shell — Xojo documentation
The Xojo Shell object is not your command line access environment. It behaves differently than Konsole or Terminal.app. Synchronous mode is waiting for the process to end.
I urge you to investigate one of the other Shell mode options, because you are trying to solve this the wrong way.
thanks. I’ve been playing around with the 3 modes and the only one that actually launches the external process is Synchronous, but then it locks the UI.
After a rethink, I came up with this as the command line: /usr/bin/udiskie &> /dev/null & disown"
and this works as expected and with Synchronous mode as well.
Clever! I’m not sure what speceific event triggers the Xojo shell to know “this shell has terminated” but sounds like this hack does the goal.
That sounds to me like the interactive or asynchronous Shell instance is going out of scope and being destroyed? In that case, your command probably is being invoked, but is killed off.