title: How to detect an application executed by a Process whether the application stops working due to an invalid input?
body: <p>I want to create a <code>LaTeX</code> editor to produce pdf documents.
  Behind the scene, my application uses <code>pdflatex.exe</code> executed through a <code>Process</code> instance.</p>
  
  <p><code>pdflatex.exe</code> needs an input file, e.g., <code>input.tex</code> as follows</p>
  
  <pre><code>\documentclass{article}
  \usepackage[utf8]{inputenc}
  \begin{document}
  \LaTeX\ is my tool.
  \end{document}
  </code></pre>
  
  <p>For the sake of simplicity, here is the minimal <code>c#</code> codes used in my <code>LaTeX</code> editor:</p>
  
  <pre><code>using System;
  using System.Diagnostics;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              Process p = new Process();
  
              p.EnableRaisingEvents = true;
              p.Exited += new EventHandler(p_Exited);
  
              p.StartInfo.Arguments = "input.tex";
              p.StartInfo.UseShellExecute = false;
              p.StartInfo.FileName = "pdflatex.exe";
  
              p.Start();
              p.WaitForExit();
          }
  
          static void p_Exited(object sender, EventArgs e)
          {
              // remove all auxiliary files, excluding *.pdf.
          }
      }
  }
  </code></pre>
  
  <p>The question is </p>
  
  <p><strong>How to detect the <code>pdflatex.exe</code> whether it stops working due to an invalid input?</strong></p>
  
  <h2>Edit</h2>
  
  <p>This is the final working solution:</p>
  
  <pre><code>using System;
  using System.Diagnostics;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              Process p = new Process();
  
              p.EnableRaisingEvents = true;
              p.Exited += new EventHandler(p_Exited);
  
              p.StartInfo.Arguments = "-interaction=nonstopmode input.tex";// Edit
              p.StartInfo.UseShellExecute = false;
              p.StartInfo.FileName = "pdflatex.exe";
              p.StartInfo.RedirectStandardError = true;
              p.Start();
              p.WaitForExit();
  
              //Edit
              if (p.ExitCode == 0)
              {
                  Console.WriteLine("Succeeded...");
              }
              else
              {
                  Console.WriteLine("Failed...");
              }
          }
  
          static void p_Exited(object sender, EventArgs e)
          {
              // remove all  files excluding *.pdf
  
              //Edit
              Console.WriteLine("exited...");
          }
      }
  }
  </code></pre>
  
  <p>The idea using <code>-interaction=nonstopmode</code> belongs to @Martin <a href="https://tex.stackexchange.com/questions/12770/how-to-prevent-pdflatex-to-stop-working-due-to-an-invalid-input-file">here</a>.</p>