Guest User

Untitled

a guest
Oct 21st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Windows.Forms;
  4.  
  5. namespace WindowsFormsApplication1
  6. {
  7. public partial class Form1 : Form
  8. {
  9. private static Process InterProc;
  10. public Form1()
  11. {
  12. InitializeComponent();
  13. InterProc = new Process();
  14. InitializeInterpreter();
  15. }
  16.  
  17. private void InitializeInterpreter()
  18. {
  19. InterProc.StartInfo.UseShellExecute = false;
  20. InterProc.StartInfo.FileName = @"C:Python27python.exe";
  21. InterProc.StartInfo.RedirectStandardInput = true;
  22. InterProc.StartInfo.RedirectStandardOutput = true;
  23. InterProc.StartInfo.RedirectStandardError = true;
  24. InterProc.StartInfo.CreateNoWindow = true;
  25. InterProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  26. InterProc.OutputDataReceived += new DataReceivedEventHandler(InterProcOutputHandler);
  27.  
  28. bool started = InterProc.Start();
  29.  
  30. InterProc.BeginOutputReadLine();
  31. }
  32.  
  33. private void AppendTextInBox(TextBox box, string text)
  34. {
  35. if (this.InvokeRequired)
  36. {
  37. this.Invoke((Action<TextBox, string>)AppendTextInBox, OutputTextBox, text);
  38. }
  39. else
  40. {
  41. box.Text += text;
  42. }
  43. }
  44.  
  45. private void InterProcOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
  46. {
  47. AppendTextInBox(OutputTextBox, outLine.Data + Environment.NewLine);
  48. }
  49.  
  50. private void Enterbutton_Click(object sender, EventArgs e)
  51. {
  52. InterProc.StandardInput.WriteLine(CommandTextBox.Text);
  53. }
  54. }
  55. }
Add Comment
Please, Sign In to add comment