B4J Question JShell continuous output

walterf25

Expert
Licensed User
Longtime User
Hi All, i was wondering if is there a way to receive the StdOut output continuously, i have a python script that I am running and i need to check the output every 1 second, the script runs for about 2 minutes, but I need to check the output every 1 second to validate the output information, is there a way to run the script and check it's output every 1 second, if so how would i go about doing this?

Thanks,
Walter
 

DonManfred

Expert
Licensed User
Longtime User
Do you mean something like this?

B4X:
Sub Process_Globals
dim t as timer
end sub
Sub AppStart (Form1 As Form, Args() As String)
    t.Initialize("Timer",500)
    ' ...
end sub

Sub btnGO_Click
    Dim args As List
    args.Initialize
    'args.Add("-oF")
    'args.Add("GTIFF")
    args.Add("-o")
    args.Add(lblDest.Text)
    For Each item As String In lv.Items
        args.Add(item)
    Next
    shl.Initialize("shl", "gdal_merge.bat" , args)
    shl.WorkingDirectory = "C:\OSGeo4W64\"
    shl.Run(-1)  ' No timeout- Let it run...
    running = True
    t.Enabled = True   ' Timer enabled
End Sub
Sub Timer_Tick
   ' change the content of the memo field with the new temporary output
    If running  Then
        memo.Text = shl.GetTempOut
    End If
End Sub
Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
   t.Enabled = False
   running = False
   If Success And ExitCode = 0 Then
       Log("Success")
       Log(StdOut)
       memo.Text = StdOut
   Else
       Log("Error: " & StdErr)
       memo.Text = StdErr
   End If
  
End Sub
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Do you mean something like this?

B4X:
Sub Process_Globals
dim t as timer
end sub
Sub AppStart (Form1 As Form, Args() As String)
    t.Initialize("Timer",500)
    ' ...
end sub

Sub btnGO_Click
    Dim args As List
    args.Initialize
    'args.Add("-oF")
    'args.Add("GTIFF")
    args.Add("-o")
    args.Add(lblDest.Text)
    For Each item As String In lv.Items
        args.Add(item)
    Next
    shl.Initialize("shl", "gdal_merge.bat" , args)
    shl.WorkingDirectory = "C:\OSGeo4W64\"
    shl.Run(-1)  ' No timeout- Let it run...
    running = True
    t.Enabled = True   ' Timer enabled
End Sub
Sub Timer_Tick
   ' change the content of the memo field with the new temporary output
    If running  Then
        memo.Text = shl.GetTempOut
    End If
End Sub
Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
   t.Enabled = False
   running = False
   If Success And ExitCode = 0 Then
       Log("Success")
       Log(StdOut)
       memo.Text = StdOut
   Else
       Log("Error: " & StdErr)
       memo.Text = StdErr
   End If
 
End Sub
I actually tried that but i don't see anything when I run shl.GetTempOut, i can see the timer running but no output at all.

Regards,
Walter
 
Upvote 0
Top