Ok I'm gonna try and explain this a little better this time. I have posted one message but none of the responses have been able to help me.
Details:
I have a program writtine in vb which sits and waits for a command via TCP/IP. When it receives the proper command it launches an application in a dos window which is a 16 bit application. I need my code to wait until the 16 bit program is completed before it continues as well I need to read what the 16bit program puts to the console.
Tried So Far:
I have tried using all the examples I have found with the following results
ReadFile - This doesn't work until the program is complete and hangs the system
ReadConsole - Doesn't seem to work at all
ReadConsoleOutputChar - this works providing I launch my program after using AllocConsole..but when I use my API to launch the console I can't read it.
The code below is ALMOST what I need...it uses AllocConsole and fires my app and even waits until it is complete but it will not close the console once I have run my app inside it.
If I can figure a way to get it to close the console that would be it
Details:
I have a program writtine in vb which sits and waits for a command via TCP/IP. When it receives the proper command it launches an application in a dos window which is a 16 bit application. I need my code to wait until the 16 bit program is completed before it continues as well I need to read what the 16bit program puts to the console.
Tried So Far:
I have tried using all the examples I have found with the following results
ReadFile - This doesn't work until the program is complete and hangs the system
ReadConsole - Doesn't seem to work at all
ReadConsoleOutputChar - this works providing I launch my program after using AllocConsole..but when I use my API to launch the console I can't read it.
The code below is ALMOST what I need...it uses AllocConsole and fires my app and even waits until it is complete but it will not close the console once I have run my app inside it.
If I can figure a way to get it to close the console that would be it
Code:
Public Function ExecCmd(ByVal cmdline$, ByVal SixteenBitApp As Boolean, Optional ByVal PathChange As String)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim BuildDirChange As String
Dim ReadingProgress As Long
ReadCMDFileCommands IIf(Right(PathChange, 1) = "\", PathChange, PathChange & "\") & _
Right(cmdline, InStr(StrReverse(cmdline), " ") - 1)
If AllocConsole() Then
ProcessConsole = GetStdHandle(STD_OUTPUT_HANDLE)
If ProcessConsole = 0 Then MsgBox "Couldn't allocate STDOUT"
Else
MsgBox "Couldn't allocate console"
End If
' Start the shelled application:
start.cb = Len(start)
'//Lets see if we should change directories
If Len(PathChange) Then ChDir PathChange
If SixteenBitApp Then cmdline = "cmd /c" & cmdline '& " > cmdlogtest.txt"
If SixteenBitApp And InStr(cmdline, "POSTODB") > 0 Then _
cmdline = "cmd /c" & cmdline
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ContinueToWait:
Read_ConsoleInformation CurPosition
DoEvents
ret& = WaitForSingleObject(proc.hProcess, 1)
DoEvents
If ret& <> 0 Then GoTo ContinueToWait
GetExitCodeProcess proc.hProcess, ret&
CloseHandle proc.hThread
CloseHandle proc.hProcess
MsgBox "Console Should Now Close"
CloseHandle ProcessConsole
FreeConsole
ExecCmd = ret&
End Function
Private Sub Read_ConsoleInformation(ReadFromTo As COORD)
Dim varConsoleGrab As CONSOLE_SCREEN_BUFFER_INFO
Dim ReadBuffer As String
Dim ConCharsRead As Long
Dim StartReadFrom As Long
Dim ReaderLoop As Long
GetConsoleScreenBufferInfo ProcessConsole, varConsoleGrab
'//First Lets Compare The Positions
Status_Window "Trying to read console"
ReadBuffer = Space(varConsoleGrab.dwSize.y * varConsoleGrab.dwSize.x)
ReadConsoleOutputCharacter ProcessConsole, ByVal ReadBuffer, Len(ReadBuffer), 0, ConCharsRead
If StoreBuffer <> ReadBuffer Then
ParseAndDisplay ReadBuffer
StoreBuffer = ReadBuffer
End If
ReadFromTo = varConsoleGrab.dwCursorPosition
End Sub
Private Sub ParseAndDisplay(NewData As String, Optional ConBufSize As Long = 80)
Dim ParseDataString As Integer
Dim DisplayIt As String
For ParseDataString = 1 To Len(NewData) Step ConBufSize
DisplayIt = RTrim(Mid(NewData, ParseDataString, ConBufSize))
If DisplayIt <> RTrim(Mid(StoreBuffer, ParseDataString, ConBufSize)) And Not EliminatePanasonicSession(DisplayIt) Then
If Len(RTrim(DisplayIt)) > 0 Then
Status_Window chkTransfering(DisplayIt)
End If
DoEvents
End If
Next ParseDataString
End Sub