B4J Question Jshell not working

marcick

Well-Known Member
Licensed User
Longtime User
tried about ten variants found here but no success.
For example this code, I have "success" in the log but the command prompt windows does not appear. Where I'm wrong ?

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    
End Sub


Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Dim shl As Shell
    shl.Initialize("shl","c:\windows\system32\cmd.exe",Null)
    shl.Run(3000)
    StartMessageLoop
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")       
    Else
        Log("Error: " & StdErr)
    End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Is this a nonui app?

If i add your code to a nonui app i get the following result which should be ok i guess....
Hello world!!!
Success
Note that shell does not open any ui window. Even not a command prompt.
Where I'm wrong ?
Not telling us what exactly you are trying to archieve.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Ah ... so the command prompt window does not appear ?
If I call a batch file I see nothing ?
If I call an exe that is a B4J Non-UI app packaged with B4J packager It is executed but I see nothing ? Any workaround in this case ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 1

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, always better to use Wait For when possible. This code will open a new console window.
B4X:
Sub AppStart (Args() As String)
    Log("Hello world!!!")
    DoSomething
    StartMessageLoop
End Sub


Sub DoSomething
    Dim shl As Shell
    shl.Initialize("shl","c:\windows\system32\cmd.exe",Array("/c", "start"))
    shl.Run(-1)
    Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")
    Else
        Log("Error: " & StdErr)
    End If
End Sub
 
Upvote 0
Top