Hi to all
I have a non UI program (ABMaterial.jar) that does not start using jshell from another UI program.
This the sub (sub already used that has always worked)
B4X:
Sub Ruwsocketws
Dim javaexe As String
javaexe = File.Combine(GetSystemProperty("java.home", ""), "bin/java")
shws.Initialize("shws", javaexe, Array ("-jar", "provaws.jar"))
shws.Run(20000)
End Sub
Sub shws_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
'Success is false and StdErr = timeout
I don't think he is running this command from ABM itself, but from an external other jar, trying to start an ABM app. But as an ABM app needs stuff (like the www folder, one should probably set the WorkingDirectory to the location of the ABM jar).
I run shell from my ABM app, to execute another standard B4J UI app to process images needed for a report (along with a pid of the record to fetch).
The ABM app jar and the charts.jar exist in the working directory (File.DirApp). Works just fine.
B4X:
Sub DoImages(pid As String)
Dim shl As Shell
shl.Initialize("shl", "java.exe", _
Array As String("-cp", "Charts.jar", "b4j.example.main", pid))
shl.WorkingDirectory = File.DirApp
shl.Run(30000) 'set a timeout of 30 seconds
End Sub
What error? Besides not starting, do you get any other error messages? What are the values of Success, ExitCode, StdOut, StdErr? If your event sub does not fire, what is the output of GetSystemProperty("java.home", ""), what is the content of javaexe? You could also use RunWithOutputEvents instead of just Run and add these two events
B4X:
Sub sh_StdOut (Buffer() As Byte, Length As Int)
Log($"StdOut: ${BytesToString(Buffer,0,Length,"utf8")}"$)
End Sub
Sub sh_StdErr (Buffer() As Byte, Length As Int)
Log($"StdErr: ${BytesToString(Buffer,0,Length,"utf8")}"$)
End Sub
loading H:\PROGET~1\PROGET~1\GWE~3\Objects\GW_Web: copymewithjar.needs...
Using cache system: 3.0
Needs material/awesome icons
Building H:\PROGET~1\PROGET~1\GWE~3\Objects\GW_Web\copymewithjar.js.needs
Building core.min.1537197941279.css...
That's normal. The app is still running. If you use a time value for Run() or RunWithOutputEvents(), that means the application should exit within that specific time. You ABM app should not (at least under normal circumstances). I think you need to use -1 for your time value.
Infact, this is the value that i usually use but in this case the sub shws_ProcessCompleted is never raised
and then i do not have the possibility to know if it is active and close after with KillProcess.
Actually, shws_ProcessCompleted is raised if and when your ABM application shuts down (be it on purpose or due to an error). If it does not get called, then the process is still running. So you could
Set a global flag, such as shws_isrunning and do
B4X:
shws_isrunning = True
shws.Run(-1)
and as long as shws_isrunning is true you can use shws.KillProcess. And in ProcessCompleted you do
B4X:
Sub shws_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
shws_isrunning = False
'Success is false and StdErr = timeout
and now you know that your application has stopped and you do not need to call KillProcess on it.