B4J Question SOLVED - JShell - and the data in StdOut

besoft

Active Member
Licensed User
Longtime User
Hello,
I am working on a project after a long time and I have a strange problem that I can't seem to solve.
I have a Python application on a raspberry Pi that needs to do something and return some information back.

There is a small application in B4J that processes and displays this. I call the Python program via jShell, which works normally. However, I don't get any information back from the Python program. When I run the py file in the terminal it returns the information normally and closes the file, I assume that everything is OK in this part because the information is correct.

What am I doing wrong to not see this information in StdOut.

B4J code:
Example:
    Dim sh As Shell
    sh.Initialize("sh", "python3", Array As String("test.py", "1000", "1000", "1000", "1000"))
    sh.WorkingDirectory = "/home/pi/motor1/"
    sh.Run(-1) 'set a timeout of 10 seconds
    
        Wait For (sh) sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        Log(StdOut)

The returned data should look something like this:
Velocity max: 1000
Raw bytes acceleration: [232, 3, 0, 0]

....

Maybe the solution is simple, I just don't see it.

THANK YOU
 

Daestrum

Expert
Licensed User
Longtime User
I would check Success flag to rule out job failure.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Try this. By using (sh) you're creating a second wait object which never fires.

B4X:
    Dim sh As Shell
    sh.Initialize("sh", "python3", Array As String("test.py", "1000", "1000", "1000", "1000"))
    sh.WorkingDirectory = "/home/pi/motor1/"
    sh.Run(-1) 'set a timeout of 10 seconds
    
    Wait For sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log(StdOut)
 
Upvote 0

teddybear

Well-Known Member
Licensed User

You need to separate the sh_ProcessCompleted from the sub.

B4X:
 ...
     Dim sh As Shell
    sh.Initialize("sh", "python3", Array As String("test.py", "1000", "1000", "1000", "1000"))
    sh.WorkingDirectory = "/home/pi/motor1/"
    sh.Run(-1) 'set a timeout of 10 seconds
       'Wait For (sh) sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
       ' Log(StdOut)
...
Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log(StdOut)
End Sub
 
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Thank you for your answers, but that didn't solve my problem either. I still don't get anything back in the B4J app.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Thank you for your answers, but that didn't solve my problem either. I still don't get anything back in the B4J app.
try this code see whether there is a stderr
B4X:
Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    
    Log(StdOut)
    log(StdErr)
    
End Sub
 
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Thank you all for your help, the secret is out

When I started the B4J program on Raspberry with "sudo", everything started working.

Greetings.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…