title: Trying to capture console output of python program in c#
body: <p>I am trying to retrieve console output of a python script by running that script in c# console application. but I don't know what I am doing wrong as I am not able to read any output. Please help me.
  This is my code sample:</p>
  
  <pre><code>Process proc = new Process();
  try
  {
  
      proc.StartInfo.FileName = "C:\\Program Files\\Python36\\python.exe";
      proc.StartInfo.Arguments = "\"E:/Database/Python Scripts/TestFile.py\" \"E:/Database/Testing.db\"";
      proc.StartInfo.UseShellExecute = false;
  
      proc.StartInfo.RedirectStandardOutput = true;
      proc.StartInfo.RedirectStandardError = true;
      proc.StartInfo.CreateNoWindow = true;
      proc.EnableRaisingEvents = true;
  
      proc.Start();
  
      while (!proc.StandardOutput.EndOfStream)
      {
          string line = proc.StandardOutput.ReadLine();
          Console.WriteLine("line:" + line);
      }
  
      Console.WriteLine("The End");
  
      Console.ReadLine();
  }
  catch(Exception ex)
  {
      Console.WriteLine("Error:{0}, Detail: {1}", ex.Message, ex.StackTrace);
  
      Console.ReadLine();
  }
  
  finally
  {
      //Console.ReadLine();
      proc.Close();
      proc.Dispose();
  }
  </code></pre>