title: How to get the error message of a Process?
body: <p>For <code>vsinstr -coverage hello.exe</code>, I can use the C# code as follows.</p>
  
  <pre><code>Process p = new Process(); 
  StringBuilder sb = new StringBuilder("/COVERAGE "); 
  sb.Append("hello.exe"); 
  p.StartInfo.FileName = "vsinstr.exe"; 
  p.StartInfo.Arguments = sb.ToString(); 
  p.Start(); 
  p.WaitForExit();
  </code></pre>
  
  <p>When there's an error, I get the error message : <code>Error VSP1018: VSInstr does not support processing binaries that are already instrumented.</code>. </p>
  
  <p>How can I get this error message with C#?</p>
  
  <h2>SOLVED</h2>
  
  <p>I could get the error messages from the answers.</p>
  
  <pre><code>using System;
  using System.Text;
  using System.Diagnostics;
  
  // You must add a reference to Microsoft.VisualStudio.Coverage.Monitor.dll
  
  namespace LvFpga
  {
      class Cov2xml
      {
          static void Main(string[] args)
          {
              Process p = new Process();
              p.StartInfo.RedirectStandardOutput = true;
              p.StartInfo.RedirectStandardError = true;         
              p.StartInfo.UseShellExecute = false; 
  
              StringBuilder sb = new StringBuilder("/COVERAGE ");
              sb.Append("helloclass.exe");
              p.StartInfo.FileName = "vsinstr.exe";
              p.StartInfo.Arguments = sb.ToString();
              p.Start();
  
              string stdoutx = p.StandardOutput.ReadToEnd();         
              string stderrx = p.StandardError.ReadToEnd();             
              p.WaitForExit();
  
              Console.WriteLine("Exit code : {0}", p.ExitCode);
              Console.WriteLine("Stdout : {0}", stdoutx);
              Console.WriteLine("Stderr : {0}", stderrx);
          }
      }
  }
  </code></pre>