473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

StreamReader::ReadLine() blocks

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
2 5328
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andy Mee | last post by:
Hello one and all, I'm developing an Asp.NET system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split()...
3
by: VMI | last post by:
When I execute a ReadLine from an ascii file with special chars (ie. the 'Ñ' in "NUÑEZ PEREZ"), it automatically deletes this character. So "NUÑEZ PEREZ" becomes "NUEZ PEREZ". How can this be...
4
by: IDandT | last post by:
Hi, I am writing a small program that connect to IRC. I create a TCPClient connection and i use stream to read and write data. It works ok, but i have a problem reading from stream. ...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
1
by: Solel Software | last post by:
Hi, When I open a text file using -- Sincerely, Mark Fox
7
by: Eric | last post by:
I am trying to save the "last read" position of a file using a StreamReader object. I am reading the lines of the file using StreamReader.ReadLine and then saving the current position in the...
1
by: Rob T | last post by:
Hi, I have a simple little program that I'm going to use to access our SMTP server. The below code works perfectly fine, but my question is if I were to try to execute the last line...
1
by: Henry | last post by:
Hi, reading a textfile with the ReadLine method of a Streamreader objects the resulting string does not contain the special characters from the source file: e.g. Paragraph § and all the umlauts...
2
by: Eddy | last post by:
I have a big problem with streamreader ReadLine()! I read from a long text files about 13k lines, than I encounter a problem: ReadLine() is not anymore able to go on! I have a string whose name is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.