title: Force StandardOutputEncoding to UTF8
body: <p>I'm looking to parse UTF8 characters from the standard output stream of another application in my C# project. Using the default approach, characters outside of the ANSI spectrum are corrupted when read from the process' standard output stream.</p>
  
  <p>Now according to Microsoft, what I need to do is set the StandardOutputEncoding:</p>
  
  <blockquote>
    <p>If the value of the StandardOutputEncoding property is Nothing, the process uses the default standard output encoding for the standard output. The StandardOutputEncoding property must be set before the process is started. Setting this property does not guarantee that the process will use the specified encoding. The application should be tested to determine which encodings the process supports.</p>
  </blockquote>
  
  <p>However, try as I might to set StandardOutputEncoding to UTF8/CP65001 the output as read, when dumped to a binary file, shows the same castration of foreign language characters. They are always read as '?' (aka 0x3F) instead of what they're supposed to be.</p>
  
  <p>I know the assumption at this point would be that the application whose output I'm parsing is simply not sending UTF8 output, but this is definitely not the case as when I attempt to dump the output of the application to a file from the commandline after forcing the codepage of the commandprompt to 65001, everything looks fine.</p>
  
  <pre><code>chcp 65001 &amp;&amp; slave.exe &gt; file.txt
  </code></pre>
  
  <p>By this, I know for a fact that the application slave.txt is capable of spitting out UTF8-encoded standard output, but try as I might, I'm unable to get StandardOutputEncoding to do the same in my C# application.</p>
  
  <p>Each and every time I end up dealing with encoding in .NET, I wish I were back in the C++ world were everything required more work but was so much more transparent. I'm contemplating writing a C application to read the output of slave.txt into a UTF8-encoded text file ready for C# parsing, but I'm holding off on that approach for now.</p>