Important point - when you run the program from the IDE, the IDE sets an environment variable with the global python folder, based on the path set under Tools - Configure Paths (or the installation folder if not set).
If you want to run the jar from the command line, with the global Python, then you need to set the environment variable:
B4X:
set B4J_PYTHON=D:\python\python
D:\java\jdk-19.0.2\bin\java -jar your_jar.jar
This is actually not the correct solution. The program will never continue after this line.
Better solution is to wait a bit before closing the program:
Waiting for debugger to connect...
Program started.
Server is listening on port: 58770
Python path: d:/python.3.12.8/python.exe
connected
starting PyBridge v0.70
watchdog set to 30 seconds
Connecting to port: 58770
PyBridge disconnected
Process completed. ExitCode: 1
Program terminated (StartMessageLoop was not called).
Private Sub Start
Py.Initialize(Me, "Py")
Dim opt As PyOptions = Py.CreateOptions("Python/python/python.exe")
Py.Start(opt)
Wait For Py_Connected (Success As Boolean)
If Success = False Then
LogError("Failed to start Python process.")
Return
End If
PrintPythonVersion
'When possible, kill the python process before exiting:
Sleep(500)
CloseProgram
End Sub
The important thing is that the template was updated and now includes the correct code.
For completeness, the Python process logs are read by B4J, using jShell library. They are not sent together with the program responses. This is important for performance reasons.
The process outputs are polled (every 50ms) so if the process is killed right after the commands were sent, they will not appear.