Let me first say i'm a VB6 newbie, so please be kind
I am trying to write a console (dosbox) app monitoring program in VB6 where i can pipe the stdout to my VB app, but i'm having a few problems. I have found several pieces of example code for piping output from console apps, but they all seem to be aimed at firing the app, grabbing a small amount of info from stdout and then closing.
What i need to do is fire up 3 console processes and then periodically check the processes are still running (restarting them if they are not) and grab the stdout from each to place in my output panels in my VB form. All 3 console apps are persistent and are expected to output quite a lot in a short amount of time.
I am starting with just one of the console apps to simplify things until i get it somewhere close to working. I can get the console app started and i'm trying to use a timer to call the stdout grabbing, it works for a few seconds then the VB form freezes until i kill the console. Once the console is gone the VB form unfreezes and dumps the rest of the output where i want it, it does always seem to freeze at about the same spot in the output though even if i change the read buffer size. I have tried different lengths between timer calls (1 second up to 30), and the number of times the timer code is successfully called before lockup varies depending on the timer length.
I've played with several examples now and seem to get the same results from each method i've tried.
Here's the current code i'm playing with (pulled from here somewhere i think)....
Any help would be greatly appreciated as i'm just stuck now!Private Sub Form_Load()
.nLength = Len(sa)
.bInheritHandle = 1 ' get inheritable pipe handles
End With 'SA
ret = CreatePipe(hPipeRead, hPipeWrite, sa, 0)
.cb = Len(si)
.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
.wShowWindow = 1 'SW_HIDE ' hide the window
.hStdOutput = hPipeWrite
.hStdError = hPipeWrite
End With 'SI
If CreateProcess(vbNullString, "c:\test\testapp1.exe", ByVal 0&, ByVal 0&, 1, 0&, ByVal 0&, "c:\test\", si, pi) Then
hPipeWrite = 0
Timer1.Enabled = True
' Call CloseHandle(pi.hProcess)
Private Sub Timer1_Timer()
If ReadFile(hPipeRead, baOutput(0), BUFSIZE, lBytesRead, ByVal 0&) = 0 Then
sOutput = Left$(StrConv(baOutput(), vbUnicode), lBytesRead)
Text1.SelText = Text1.SelText + sOutput