B4J Question jShell doesn't launch external app

DaleA

Member
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.

Environment:
Windows 10
B4J 9.10
jShell 1.52

Where did I get it wrong?
 

MarcoRome

Expert
Licensed User
Longtime User
In which folder do you have BookTraker.exe ?
Try
B4X:
    Dim shl As Shell

    shl.Initialize("shl", "C:/Folderwhereisfile/BookTracker.exe", Null)
    shl.Run(-1)
    Log("External App should be running")
 
Upvote 0

DaleA

Member
In which folder do you have BookTraker.exe ?
Try
B4X:
    Dim shl As Shell

    shl.Initialize("shl", "C:/Folderwhereisfile/BookTracker.exe", Null)
    shl.Run(-1)
    Log("External App should be running")
I've already tried with the path fully qualified (sorry - old jargon for using the full path name) without success.
B4X:
   Dim shl As Shell

    shl.Initialize("shl", "D:\TMP\BookTracker\BookTracker.exe", Null)
    shl.WorkingDirectory ="D:\TMP\BookTracker"
    shl.Run(-1)

didn't work either.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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)
What is the output of this code?
 
Upvote 0

DaleA

Member
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?
 
Upvote 0

dongsool

Member
Licensed User
Longtime User
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)
 
Upvote 0
Top