title: Python script output redirection using C#
body: <p>this question could seem as duplicate, i have tried all the suggested solution but in vain , i wanna redirect python script output using this code :</p>
  
  <pre><code>    System.Diagnostics.Process proc = new System.Diagnostics.Process();
      proc.StartInfo.FileName = "python.exe";
      proc.StartInfo.Arguments = Application.StartupPath.Replace("\\bin\\Debug", "") + "\\scripts\\test.py";
      proc.OutputDataReceived += OutputDataReceived;
      proc.ErrorDataReceived += ErrorDataReceived;
  
      proc.StartInfo.RedirectStandardOutput = true;
      proc.StartInfo.UseShellExecute = false;
      proc.StartInfo.CreateNoWindow = true;
      proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
  
      proc.Start();
      //proc.WaitForExit();
  
      StringBuilder q = new StringBuilder();
      while (!proc.HasExited)
      {
          q.Append(proc.StandardOutput.ReadToEnd());
      }
      string r = q.ToString();
      r = proc.StandardOutput.ReadToEnd();
      MessageBox.Show(r);
  }
  private void OutputDataReceived(object sender, DataReceivedEventArgs args)
  {
      //textOutput.Text += args.Data;
      MessageBox.Show(args.Data);
  }
  </code></pre>
  
  <p>the python script contains <code>print "hello test"</code> i tried unbuffering output but vainly.</p>
  
  <p>Any help please.</p>
  
  <p>I'm using VS 2010 .NET 4.0 , Python 2.7 , winXP sp3.</p>