B4J Question Problems with calling a batch file from B4J

kpmais

Member
Licensed User
Longtime User
Hello everyone,
I hope for your help with the following problem:

I am dynamically creating a batch file.

This batch file calls a SQLite database and creates a JSON file from any table.

I am now calling this batch file from B4J.

I have tried 2 variants for this call so far.

a) via the JShell library

b) via the JAWTRobot library

The calls to both libraries do not return an error.

But neither library leads to a result and no shell environment (cmd) is opened.

Calling the created batch file from Explorer works without problems and delivers the desired result.

The content of the batch file must be correct.

The following code:

Creating the batch file:

B4X:
    Dim RString As String = "sqlite3 D:\B4A_Programs\Databases\d4h.sqlite" & " -cmd " & """.mode json""" & " -cmd " & """.once mytest.out""" & " -cmd " & """select * from glucose where datum like('10.10.%');"""

    File.WriteString("D:\B4A_Programs\Databases\","tjson_1.bat",RString)
    Dim mybatchfile As String = File.Combine("D:\B4A_Programs\Databases","tjson_1.bat")

Calling via the JShell library:

B4X:
    shl as jshell
shl.Initialize("shl",mybatchfile , Null)
    shl.Run(-1)

and the event procedure:

B4X:
Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log($"Success: ${Success},
Out: ${StdOut}
Error: ${StdErr}"$)
End Sub

Calling via the JAWTRobot library:

B4X:
Dim jawt As AWTRobot

Log(jawt.SystemRunCommand(mybatchfile ))

Is it perhaps a problem to call a batch file from B4J in general?

I really hope you can help me.
Thank you in advance for your effort.
 

teddybear

Well-Known Member
Licensed User
What is the log?
Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Log($"Success: ${Success},
Out: ${StdOut}
Error: ${StdErr}"$)
End Sub
 
Upvote 0

kpmais

Member
Licensed User
Longtime User
Thank you for answer.

The Log is:
Success: true,
Out:
D:\B4J_PR~1\SQLADM~1\SqlAdmin\Objects>sqlite3 D:\B4A_Programs\Databases\d4h.sqlite -cmd ".mode json" -cmd ".once mytest.out" -cmd "select * from glucose where datum like('10.10.');"
Error:
 
Upvote 0

kpmais

Member
Licensed User
Longtime User
When i set the batch file to:
"start """ & """ sqlite3 D:\B4A_Programs\Databases\d4h.sqlite" & " -cmd " & """.mode json""" & " -cmd " & """.once mytest.out""" & " -cmd " & """select * from glucose where datum like('10.10.%');"""

he's open the cmd window, but after closing the window i get the log:
Success: false,
Out:
Error: org.apache.commons.exec.ExecuteException: The stop timeout of 500 ms was exceeded (Exit value: -559038737)
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Thank you for answer.

The Log is:
Success: true,
Out:
D:\B4J_PR~1\SQLADM~1\SqlAdmin\Objects>sqlite3 D:\B4A_Programs\Databases\d4h.sqlite -cmd ".mode json" -cmd ".once mytest.out" -cmd "select * from glucose where datum like('10.10.');"
Error:
It should be completed, Success is true
D:\B4J_PR~1\SQLADM~1\SqlAdmin\Objects>sqlite3 D:\B4A_Programs\Databases\d4h.sqlite -cmd ".mode json" -cmd ".once mytest.out" -cmd "select * from glucose
This message just is cmd line output. remove the option "".once mytest.out" , you can see the json result.
check out the file mytest.out, it is in FIle.DirApp
 
Last edited:
Upvote 0
Top