B4J Question Jshell not work with ABMaterial.jar

micro

Well-Known Member
Licensed User
Longtime User
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
Why shell not work?
Thanks
 

OliverA

Expert
Licensed User
Longtime User
Where is this code located in your ABMaterial application?
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Where is this code located in your ABMaterial application
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).
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
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
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Maybe you will have to set the shws.WorkingDirectory too?
The same error with
B4X:
shws.WorkingDirectory = File.DirApp

Where is this code located in your ABMaterial application?
Not of course, if you read well I say ....... 'using jshell from another UI program'

probably set the WorkingDirectory to the location of the ABM jar
The ABM jar and related folders is in the same location of the UI jar. (File.DirApp)

Thanks
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Not of course, if you read well I say
My excuse: It's Monday and I need way more coffee
The same error with
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
and maybe see what is going on
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
the output of GetSystemProperty("java.home", "")
It's correct = C:\Program Files (x86)\Java\jdk1.8.0_171\jre\bin\java

What are the values of Success, ExitCode, StdOut, StdErr?
Success = False
ExitCode = 1
SdtOut=
B4X:
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...

StdError= timeout (also with 50000)

Thanks
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
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.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
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.

Thanks for your patience
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
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.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Ok OliverA, I agree with your advice....not very elegant but for now it seems to me the quickest way.

Thanks and do not drink too much coffee ;)
Best regards
 
Upvote 0
Top