StreamReader::ReadLine() blocks

G

Guest

I am trying to read the output of an external application using redirected
stdout and StreamReader::ReadLine(). The problem is that ReadLine() blocks
and I am either reading nothing or just part of the output.

I start a new process from my app to run the external app.
StartInfo.RedirectStandardOutput is set to true.

Then I start a thread that just keep reading the standard output of this new
process in an infinite loop using ReadLine().

When I try running it, ReadLine() blocks until I kill the external app
process. The external app is outputing something because I am running
another instance in a command prompt and I can see the output (running
multiple instances does not affect how the external app works).

If I put a breakpoint at the ReadLine() call and then step through it, it
will read some of the output but still block after a while. I tried using
TextReader.Synchronized() to get a thread-safe reader but it still blocks.

My understaning is that ReadLine() will block until a line is read but it
doesn't seem to work this way. How can I solve this problem?

Thanks.
 
J

Jon Skeet [C# MVP]

Kin said:
I am trying to read the output of an external application using redirected
stdout and StreamReader::ReadLine(). The problem is that ReadLine() blocks
and I am either reading nothing or just part of the output.

<snip>

Are you absolutely sure the app is writing to stdout and not to stderr?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.


(By the way, posting again less than a day later just to get attention
isn't terribly polite, IMO.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top