reading from a process sdtout

P

palaga

Hi
I'm starting an external process that writes data to stdout, and I want to
get back these data.
So I use myProcess.StandardOutput (everything is correctly set, I can read
the data).

to read data, I use myProcess.StandardOutput.ReadLine( ). (the data is
text). The doc says that if there is no more data available, the function
ReadLine return null.

This does not seem to work with the standard output stream of a process...
If there is no data available, the ReadLine blocks, and returns only when it
gets data, or the process ends.
So I tried to use Peek() to see if there are data, before calling
readline... no way, stdout is not seek-able, so peek() always return -1.
I also tried to use Read(), and it doe snot work as well...

How can I know if there are data available in my process standard output
stream ?
 
N

Nicholas Paldino [.NET/C# MVP]

palaga,

The only way that no more data will be available will be if the process
shuts down. The stream can't know if there is any more data to be read
from, because it is still open, and could possibly have more data coming
down the line.

If anything, you will have to parse the messages, and know what to
expect, so you know when to start and stop reading.

Hope this helps.
 
P

palaga

Thanks for your answer...
At least, I know now that this is not possible...


Nicholas Paldino said:
palaga,

The only way that no more data will be available will be if the process
shuts down. The stream can't know if there is any more data to be read
from, because it is still open, and could possibly have more data coming
down the line.

If anything, you will have to parse the messages, and know what to
expect, so you know when to start and stop reading.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

palaga said:
Hi
I'm starting an external process that writes data to stdout, and I want to
get back these data.
So I use myProcess.StandardOutput (everything is correctly set, I can read
the data).

to read data, I use myProcess.StandardOutput.ReadLine( ). (the data is
text). The doc says that if there is no more data available, the function
ReadLine return null.

This does not seem to work with the standard output stream of a process...
If there is no data available, the ReadLine blocks, and returns only when
it
gets data, or the process ends.
So I tried to use Peek() to see if there are data, before calling
readline... no way, stdout is not seek-able, so peek() always return -1.
I also tried to use Read(), and it doe snot work as well...

How can I know if there are data available in my process standard output
stream ?
 

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