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")
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
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.
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.
I do not have any special code. I could'nt make it work so I stopped before start developing related library. Simple console application with code below.
Added also StartMessageLoop with no change on result.
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Dim systemType As String
'Dim utils As serverStatUtils
Dim EOL As String = Chr(13)&Chr(10)
End Sub
Sub AppStart (Args() As String)
Try
Dim shl As Shell
shl.Initialize("shl", "/usr/bin/mpstat", Array("-P","ALL"))
shl.WorkingDirectory = "/"
shl.RunWithOutputEvents(6000)
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")
StartMessageLoop
End Sub
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Dim systemType As String
'Dim utils As serverStatUtils
Dim EOL As String = Chr(13)&Chr(10)
End Sub
Sub AppStart (Args() As String)
Try
Dim shl As Shell
shl.Initialize("shl", "/usr/bin/mpstat", Array("-P","ALL"))
shl.WorkingDirectory = "/"
shl.RunWithOutputEvents(6000)
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")
StartMessageLoop
End Sub