B4J Question Nonui and standalone package

giggetto71

Active Member
Licensed User
Longtime User
Hi,
I have a very simple nonui B4j app that works fine when I call it from "java -jar nonui.jar".
When I build it as exe it behaves strangely.
here's the code. very simple. it processes 3 commands "inc" (which increases an int), "dec" which decrements it, and "quit" to terminate the app .

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

Sub Process_Globals
    Private reader As TextReader
    Public ii As Int
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Dim Wend As Boolean
    Dim sys As JavaObject
    If Args.Length >0 Then
       Log(Args(0))
    End If
    sys.InitializeStatic("java.lang.System")
    reader.Initialize(sys.GetField("in"))
    Wend =True
    
    Do While Wend
      
       Log("Enter command>: ")
       Select ReadLine
          Case "quit"
             Wend = False
             ExitApplication2(0)
          
        Case "inc"
             ii = ii+1
             Log (ii)
        Case "dec"
             ii = ii-1
             Log (ii)   
       End Select
    Loop     
    
   StartMessageLoop   
End Sub

Sub ReadLine As String
   Log("readlineok")
   Return reader.ReadLine
End Sub


when I run it from "java -jar nonui.jar" I get the expected result:

INI:
C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects>java -jar nonui.jar
Hello world!!!
Enter command>:
readlineok
inc
1
Enter command>:
readlineok
inc
2
Enter command>:
readlineok
dec
1
Enter command>:
readlineok
quit

C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects>


when I compile it and run it as exe I get:
INI:
C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects\temp\build>nonui

C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects\temp\build>Hello world!!!
Enter command>:
readlineok
inc
'inc' is not recognized as an internal or external command,
operable program or batch file.

C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects\temp\build>inc
1
Enter command>:
readlineok
inc
'inc' is not recognized as an internal or external command,
operable program or batch file.

C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects\temp\build>inc
2
Enter command>:
readlineok
dec
'dec' is not recognized as an internal or external command,
operable program or batch file.

C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects\temp\build>dec
1
Enter command>:
readlineok
quit
'quit' is not recognized as an internal or external command,
operable program or batch file.

C:\b4a_projects\B4J_Projects\TestConsole\NonUI\Objects\temp\build>

basically it seems like in the exe version the reader works after pressing return which also shows the entire path and seems to ignore the instruction Log("Enter command>: ")

any idea?
thanks
 

Sagenut

Expert
Licensed User
Longtime User
I noticed that launching the EXE with double click from the folder make it work correctly.
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
thanks @Sagenut , that it true! it happens here too. unfortunately I need to run it from command line as I will have to use to interface it with another program. any other ideas?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Instead of
B4X:
nonui.exe
use
B4X:
start nonui.exe
You could make a file called Launch.Bat (just as an example) that contain that command and call it to open your app.
Don't know if it will make your app interact with others as you need.
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
Ok, at the end i managed to use the jar file for my case so i did not use the exe. I needed to interface my chess engine with other engines using xboard protocol and fortunately winboard allows to specify the name,path of the "exe" even for jar files as basically in that case, i believe, it considers "java" as the executable..so i was able to read and write stdio. Btw, @Erel, thanks for the fact that log writes to the stdio..soo convenient!
 
Upvote 0
Top