StreamReader problem. What am I doing wrong?

StreamReader problem. What am I doing wrong?

Post by QmFnZ2V » Thu, 04 Aug 2005 06:43:20

I'm trying to build an app (in VB.Net) that will interact with various
console applications. It's interaction is pretty simple. It will just send
commands to the standard input stream, and retrieve output from the standard
output and standard error streams. The trickiness comes from the fact that
it must be a multithreaded app to do this properly, and while I think I have
it set up correctly, I'm having a problem getting the output from the
standard output stream. I set the UseShellExecute property of the process to
false, and redirected standardinput, standardoutput and standarderror. I
spawn threads to listen to the two output streams. Here's the sub that is
passed to the thread and does the listening to standardoutput (Sreader is the
standardoutput stream):

Public Sub Read()
Dim val As Integer

While ((val = Sreader.Read()) >= 0)
RaiseEvent ReadStreamCompleted(Me, New
ReadStreamEventArgs(Chr(val).ToString, strName))
End While

End Sub

That's it. Now, all it returns is zeros. But it DOES return the proper
number of zeros to match the number of expected characters in the output. I
have no idea why that is. Can anyone tell me what I'm doing wrong here? I
can't find anything more than the most simplistic examples of interacting
with console apps on the web, and all the books I've looked in haven't been
much more helpful either.

Nothing seems to explain how to simply return all the output that a console
app generates, basically in real time, until the application closes. That's
what I need. Any help is appreciated. Thanks!