Hello, I am trying to make a way to manage instances of an .EXE software remotely, I need to run and close this application, I am trying to use JShell to manage all instances that are running so that at any time I can close them, run new ones instances or even terminate those that are running ...
but when I run it directly from the .exe executable, it works well, when I run it through JShell it doesn't work well ...
see the screenshots below:
(running directly from the executable)
When the application is launched from the shell, the output is redirected to the StdOut variable.
In your code you only read this variable when the application is stopped successfully (see controller_ProcessCompleted). However in your code you exit the application by timeout (error) and never read StdOut
If you want to read the content of the output while the application is running, you have to use for example : controller.GetTempOut
When the application is launched from the shell, the output is redirected to the StdOut variable.
In your code you only read this variable when the application is stopped successfully (see controller_ProcessCompleted). However in your code you exit the application by timeout (error) and never read StdOut
If you want to read the content of the output while the application is running, you have to use for example : controller.GetTempOut
interesting ...
but I noticed that I can only "read" the stdout only when the application is closed ...
can I read and write to the application's stdout and stdin using PIPE?
while application is running :
B4X:
Waiting for debugger to connect...
Program started.
Hello world!!!
while application is closed :
B4X:
Waiting for debugger to connect...
Program started.
Hello world!!!
STDOUT = Waiting 5 secs before quit...
Waiting 4 secs before quit...
Waiting 3 secs before quit...
Waiting 2 secs before quit...
Waiting 1 secs before quit...
Loop Forever now ...
Success
as mentioned in my answer above : " If you want to read the content of the output while the application is running, you have to use for example : controller.GetTempOut"
so for example you add a timer, and in the timer tick event, read the GetTempOut and GetTempErr (which returns the complete content of Sdout/StdErr on each reading )
B4X:
Sub AppStart (Args() As String)
...
Dim timer1 As Timer
timer1.Initialize("Timer1", 200)
timer1.Enabled = True
controller.Run(-1)
...
StartMessageLoop
End Sub
Sub Timer1_Tick
Log("tick :")
Log(controller.GetTempOut)
Log(controller.GetTempErr) ' if needed
End Sub
Another approach is to use the RunWithOutputEvents method which produces a StdOut or StdErr event whenever data is available on the standard or error output.
Example below
B4X:
Sub AppStart (Args() As String)
...
controller.RunWithOutputEvents(-1)
...
StartMessageLoop
End Sub
Sub controller_StdOut (Buffer() As Byte, Length As Int)
Log("Stdout : " & BytesToString(Buffer, 0, Length, "UTF8"))
End Sub
Sub controller_StdErr (Buffer() As Byte, Length As Int)
Log("StdErr : "& BytesToString(Buffer, 0, Length, "UTF8")
End Sub