Capturing binary output from Process.StandardOutput

Using StandardOutput.BaseStream is the correct approach, but you must not use any other property or method of cmdProcess.StandardOutput. For example, accessing cmdProcess.StandardOutput.EndOfStream will cause the StreamReader for StandardOutput to read part of the stream, removing the data you want to access.

Instead, simply read and parse the data from br (assuming you know how to parse the data, and won’t read past the end of stream, or are willing to catch an EndOfStreamException). Alternatively, if you don’t know how big the data is, use Stream.CopyTo to copy the entire standard output stream to a new file or memory stream.

Leave a Comment