tags:

views:

67

answers:

3

Any ideas on how to discard or reset the contents in a Process.StandardOutput, so we can discard the message of the day and any other initial content of a process?

A: 

I don't know what you mean by discard but you may redirect the standard output:

When a Process writes text to its standard stream, that text is typically displayed on the console. By redirecting the StandardOutput stream, you can manipulate or suppress the output of a process.

Darin Dimitrov
I'm already redirecting it to a reader. What I need to do is actually discard the contents of the underlying stream before the reader uses it
jacko
+1  A: 

You could to try something similar to:

Process.StandardOutput.BaseStream.SetLength(0);

process.StandardOutput.ReadToEnd();

That way you'll read all content already written and to ignore it. Since that stream doesn't supports seek operations, you user will receive a "headerless" stream.

Rubens Farias
System.NotSupportedException: Stream does not support seeking.
jacko
+1  A: 

Does Process.StandardOutput.DiscardBufferedData() not do what you want?

Alternatively just read from it until it's empty? Not very efficient I guess, but if it's just title fluff then it'll be one read.

JonB