I am executing a .exe with b4j and this .exe is writing me a file while it is executing then it stops and the file finishes writing.i an trying to read this file but since it does not finishes when my line of reading executes then it only reads part of it. Is there a way to wait for the .exe to finish so i can read the hole file written by it?
Dim shl As Shell
shl.Initialize("shl", ...)
shl.Run(-1)
Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Log(Success)
Log(StdOut)
Log(StdErr)
'read file here
I am using a .bat to run the .exe since because if i run the .exe directly it takes more space. the code you rote could work with a .bat too? cause i am trying to use it but it does not wait...
it just jumps and never returns to the sub where i have your code.
I have tried using it in different ways:
Way 1:
B4X:
run(".bat",Null)
Sub run (EXE As String, code As List) As ResumableSub
Dim shl As Shell
shl.Initialize("shl",EXE,code)
shl.Run(-1)
Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Log(Success)
Log(StdOut)
Log(StdErr)
'
Return ""
End Sub
Way 2:
B4X:
Dim shl As Shell
shl.Initialize("shl",".bat",Null)
shl.Run(-1)
Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Log(Success)
Log(StdOut)
Log(StdErr)
all this is inside a sub of a function that is inside a loop since I'm iterating many times through the launch if the .bat. So, what "Wait for" does is to go out of the sub where it is and then doo the iterative process. this causes the wait for to never be completed since it will complete until finishing the sub that contains the loop.
I hope i explained myself right so that you can understand and help.
It is a "feature" of the of the program i am executing. if the program is executed with a .bat, it only uses the necessary to solve what i'm asking him.