Redirecting StandardOut

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am running a console program through my own VB front end. I am redirecting the StandardOut and StandardInput streams to and from textboxes so that the VB front end acts like a console. My problem is that the console program outputs a message, then a newline, then a prompt character (<message><newline>"> "), but I can only seem to read the StandardOut stream by line. So the prompt character is never shown, since the stream is only read to the newline. The prompt does not show up until another newline is added to the output stream. Is there any way to flush the output stream or not have it buffered by newline

The code I am working with is similar to this
<http://www.mvps.org/dotnet/dotnet/samples/miscsamples/downloads/RedirectConsole.zip
(if you run this, you will notice that you not receive the command prompt when you should - the same type of problem I am having

Thanks
Tim
 
* =?Utf-8?B?VGlt?= said:
I am running a console program through my own VB front end. I am
redirecting the StandardOut and StandardInput streams to and from
textboxes so that the VB front end acts like a console. My problem is
that the console program outputs a message, then a newline, then a
prompt character (<message><newline>"> "), but I can only seem to read
the StandardOut stream by line. So the prompt character is never shown,
since the stream is only read to the newline. The prompt does not show
up until another newline is added to the output stream. Is there any
way to flush the output stream or not have it buffered by newline?

You may want to use 'Read' intstead of 'ReadLine', but notice that this
will return an integer for each character read from the stream. You can
use the 'Chr' function to convert it to a character. If feel sorry, but
I don't have enough time at the moment to play around with that.
 
Hi

Thank you for helping me again. I did try Read. I read each character and appended it to the textbox's text - this resulted in an annoying flickering though. I then tried appending the characters to a string with the intention of appending the string to the textbox's text at some point, but since the loop is infinite, that didn't work. Any ideas of how to use read without having the textbox flicker as often as it does

Thank you
Tim
 
* =?Utf-8?B?VGlt?= said:
character and appended it to the textbox's text - this resulted in an
annoying flickering though. I then tried appending the characters to a
string with the intention of appending the string to the textbox's text
at some point, but since the loop is infinite, that didn't work. Any
ideas of how to use read without having the textbox flicker as often as
it does?

I played around with it but I didn't get it work (I only tried some
minutes).

:-(
 
* =?Utf-8?B?VGlt?= said:
I found away around the flickering - though it is in some ways a quick
hack to make it work. I write the characters to a string until I reach
certain characters that normally denote the end of a line or message in
the output of the program ":", ".", ">". When I reach one of these, I
append it to the string, then append the string to the textbox and start
over again. I lowers the amount of updates done to the textbox but will
only work for the specific output that comes from the program I am
running.

Can you post parts of your code?
 
Here is the changes I made to the function that you wrote:

Private Sub StreamOutput()
Dim letter As Integer = m_Process.StandardOutput.Read()
Dim strLine As String
Dim output As String = ""
Try
If letter = 10 Then
strLine = ControlChars.NewLine
Else
strLine = Convert.ToChar(letter)
End If

Do While strLine.Length >= 0
If strLine.Length <> 0 Then
output += strLine
If strLine.Equals(">") Or strLine.Equals(".") Or strLine.Equals(":") Then
txtConsole.AppendText(output)
output = ""
End If
End If

letter = m_Process.StandardOutput.Read()
If letter = 10 Then
strLine = ControlChars.NewLine
Else
strLine = Convert.ToChar(letter)
End If
Loop
Catch
MenuRun.Enabled = True
End Try
End Sub

I had to read to an integer first to account for the newline since VB does not recognize C++ escape characters.

-Tim
 
Back
Top