I'm trying to launch an external app from my B4j Windows app using the following code:
B4X:
Private Sub pg2Btn_Click
Log("Pg 2 button clicked")
Dim shl As Shell
shl.Initialize("shl", "BookTracker.exe", Null)
shl.WorkingDirectory ="D:\TMP\BookTracker"
shl.Run(-1)
Log("External App should be running")
End Sub
The external app does not need any command line parameters. I get no indication of an error but the app doesn't launch. It doesn't make any difference if I include the fully qualified path in the Initialize statement.
1. WorkingDirectory is not related here. It only affects the new process behavior.
2. This code is incomplete.
3. Correct code:
B4X:
Dim shl As Shel;
shl.Initialize("shl", "D:\TMP\BookTracker\BookTracker.exe", Null)
shl.Run(-1)
Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Log(Success)
Log(ExitCode)
Log(StdOut)
Lot(StdErr)
Thanks, Erel. That worked, mostly. The intent is to start the external application and have the calling app be totally independent of the external app. If the user closes the calling app while the external app is still running, the calling app still needs to close completely without having to wait for the external app to close. Am I using the wrong approach?
I can't do it the above way. I succeeded in this way.
B4X:
Dim shl As Shell
shl.Initialize("shl", "cmd", Array("/c", "C:\launcher\launcher.exe"))
shl.Run(-1)
Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Log(Success)
Log(ExitCode)
Log(StdOut)
Log(StdErr)