By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,367 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,367 IT Pros & Developers. It's quick & easy.

StreamReader::ReadLine() blocks

P: n/a
Kin
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.
Mar 22 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Kin
(BUMP)
Anyone please?
"Kin" wrote:
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.

Mar 22 '06 #2

P: n/a
Kin <Ki*@discussions.microsoft.com> wrote:
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.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.