Console Program Input/Output

Just starting out? Need help? Post your questions and find answers here.
User avatar
bgeraghty
User
User
Posts: 52
Joined: Wed Apr 02, 2014 12:45 am
Location: irc.ibotched.it:+6697
Contact:

Console Program Input/Output

Post by bgeraghty »

Hello,

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
Basically, I am trying to get openssl.exe to connect to my server using ssl, and then allow me to send a few lines of raw text back and fourth for debugging/testing, but it seems to stop allowing input as soon as it is running. I've done exhaustive searching on this and other forums, but everything shares this strange issue. maybe openssl.exe is unique?

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
SolveMyIssue_() - No QuickHelp available.
User avatar
bgeraghty
User
User
Posts: 52
Joined: Wed Apr 02, 2014 12:45 am
Location: irc.ibotched.it:+6697
Contact:

Re: Console Program Input/Output

Post by bgeraghty »

Update:

I have worked around this by using GnuTls-CLI, which is fine for my basic purposes here.

It seems that with OpenSSL, there is some kind of change taking place when the connection is established with how input is accepted into the program. I'm not sure how one would get around this using RunProgram + WriteProgramX or CreatePipe_(), as both seemed to have the child process not responding to input at a certain point.
SolveMyIssue_() - No QuickHelp available.
Post Reply