B4J Question Shell.run no output

Alpay ABAY

Member
Licensed User
I tried a few different ways, I couldn't make this shell output work.
I tested .jar on ubuntu, when I run same code it works.
Not raising also any exception. It is a console application.
Looks like when I make shell call, application stops working. Never reaches to Log("Operation complete")

Please if anyone knows why ?

B4X:
    Try
        Dim shl As Shell
        shl.Initialize("shl", "/usr/bin/mpstat", Array("-P","ALL"))
        shl.Run(-1)
        Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        Log("done")
        Log("Ecode:"&ExitCode)
        Log("Error:"&StdErr)
        Log("out:"&StdOut)
        Log("Status:"&Success)
    Catch
        Log("Error execution")
        Log(LastException)
    End Try 
    Log("Operation complete")
 

Attachments

  • ubuntu-preview.png
    ubuntu-preview.png
    8 KB · Views: 11

teddybear

Well-Known Member
Licensed User
I guess you are using Non-UI app, you need to do StartMessageLoop waiting for shl_ProcessCompleted .
Try this code
B4X:
Sub AppStart (Args() As String)
        Dim shl As Shell
        shl.Initialize("shl", "/usr/bin/mpstat", Array("-P","ALL"))
        shl.Run(-1)
        StartMessageLoop
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        Log("done")
        Log("Ecode:"&ExitCode)
        Log("Error:"&StdErr)
        Log("out:"&StdOut)
        Log("Status:"&Success)
        Log("Operation complete")
        StopMessageLoop
End Sub
 
Last edited:
Upvote 0

Alpay ABAY

Member
Licensed User
I guess you are using Non-UI app, you need to do StartMessageLoop waiting for shl_ProcessCompleted .
Try this code
B4X:
Sub AppStart (Args() As String)
        Dim shl As Shell
        shl.Initialize("shl", "/usr/bin/mpstat", Array("-P","ALL"))
        shl.Run(-1)
        StartMessageLoop
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        Log("done")
        Log("Ecode:"&ExitCode)
        Log("Error:"&StdErr)
        Log("out:"&StdOut)
        Log("Status:"&Success)
        Log("Operation complete")
        StopMessageLoop
End Sub
Thanks, but It is not relating to that. StartmessageLoop only wait main thread, but i call it with wait for to collect output and return, also your method with fail. I have various calls.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Thanks, but It is not relating to that. StartmessageLoop only wait main thread, but i call it with wait for to collect output and return, also your method with fail. I have various calls.
The code works here. this's the result.
result.png


I don't know why it does not work your there. you'd better upload a small project for the question.
 
Last edited:
Upvote 0
Top