title: Process.Start random stops during the middle of the execution
body: <p>I need to call an external program to download e-mails into a folder. This external program is a <code>Java</code> compiled with Excelsior JET (Jar to Exe).</p>
  
  <p>This is how I call:</p>
  
  <pre><code>var process = new Process
  {
      StartInfo =
      {
          Arguments = Arguments(folder),
          FileName = Path.Combine(@"C:/Fakepath"), "GetMail.exe"),
          CreateNoWindow = true,
          UseShellExecute = false,
          RedirectStandardError = true,
          RedirectStandardOutput = true
      }
  };
  
  process.Start();
  process.WaitForExit();
  
  var output = process.StandardOutput.ReadToEnd();
  var outputError = process.StandardError.ReadToEnd();
  
  //if (!String.IsNullOrEmpty(output))
  //    LogWriter.Log("GetMail", output.Trim());
  
  if (!String.IsNullOrEmpty(outputError))
        LogWriter.Log("GetMail Erro", outputError.Trim());
  
  process.Close();
  </code></pre>
  
  <p>I guess it has something wrong with the output, like <a href="https://stackoverflow.com/questions/2471656/why-does-ffmpeg-stop-randomly-in-the-middle-of-a-process">this other thread here</a>.</p>
  
  <p>The <code>Java</code> app stops where it shouldn't, like, between two Log calls:</p>
  
  <pre><code>try
  {
      for (Address addr : msg.getFrom())
      {
          AppConfig.getLogControl().WriteLog("\tFrom.............:" + addr);
      }
  } catch (Exception e) { }
  
  MimeMessage msgMIME = null;
  
  try
  {
      AppConfig.getLogControl().WriteLog("\tTesting message type... ");
      msg.isMimeType("text/*");
      AppConfig.getLogControl().WriteLog("\t\tMultipart type");
  } catch (MessagingException ex)
  {
      AppConfig.getLogControl().WriteLog("\t\tMIME type");
      AppConfig.getLogControl().WriteLog("\tDownloading data... ");
      msgMIME = TrataMimeMessage(msg);
  }
  </code></pre>
  
  <p>It prints "From...." and stops, if I kill the <code>C#</code> process, the <code>Java</code> app continues to print the rest.</p>
  
  <h2>Edit</h2>
  
  <p>After <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx?f=255&amp;MSPPError=-2147217396" rel="nofollow noreferrer">reading this page</a>, I think I know what I'm doing it wrong.
  One of the sections of the MSDN page:</p>
  
  <pre><code> // To avoid deadlocks, always read the output stream first and then wait.
   string output = p.StandardOutput.ReadToEnd();
   p.WaitForExit();
  </code></pre>