I am trying to have my Purebasic program perform an external "session" with another console program (openssl.exe), where it runs the program, and then reads strings, and writes my input strings back to the program, until it (openssl.exe process) ends. ( Using : https://indy.fulgan.com/SSL/openssl-1.0 ... -win32.zip) Trying to keep things simple here, but I am running into an issue:
The program launches, and I see all of the output in debug until the connection closes due to a time-out, however after it starts, it stops responding to my WriteProgramStringN() or WriteProgramData() calls, and I can no longer provide input to the program.
Sample Code:
Code: Select all
Procedure OutputThread(App)
While ProgramRunning(App)
If AvailableProgramOutput(App)
Tmp$ = ReadProgramString(App)
;If Left(Tmp$, 1) = ":"
Debug Tmp$
Delay(5)
;EndIf
EndIf
Wend
EndProcedure
OpenConsole()
App = RunProgram("bin\openssl.exe", "s_client -connect 198.12.101.204:6697", GetCurrentDirectory(), #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Error)
If App
CreateThread(@OutputThread(), App)
While ProgramRunning(App)
Temp$ = Input()
WriteProgramStringN(App, Temp$, #PB_UTF8)
Wend
Debug "Exitcode: " + Str(ProgramExitCode(App))
CloseProgram(App)
EndIf
When I run the following code, (using "cmd.exe" instead), I am able to input to the console, and debug the output as long as I like:
Code: Select all
Procedure OutputThread(App)
While ProgramRunning(App)
If AvailableProgramOutput(App)
Tmp$ = ReadProgramString(App)
;If Left(Tmp$, 1) = ":"
Debug Tmp$
Delay(5)
;EndIf
EndIf
Wend
EndProcedure
OpenConsole()
App = RunProgram("cmd.exe", "", GetCurrentDirectory(), #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Error)
If App
CreateThread(@OutputThread(), App)
While ProgramRunning(App)
Temp$ = Input()
WriteProgramStringN(App, Temp$, #PB_UTF8)
Wend
Debug "Exitcode: " + Str(ProgramExitCode(App))
CloseProgram(App)
EndIf
I'm using x86 PureBasic 5.41, but have tested this on 5.45 as well as 5.61 with same results. Also have tested on Windows 10, Windows Server 2012.
Any Ideas?
Thank you