title: Making embedded console in WinForms
body: <p>I am working on a sort of IDE-like program in WinForms in Visual Studio 2010 with C#. I've gotten it to work with two textboxes, two buttons, and a console window. The first textbox is used for writing C# code, which is compiled using <code>CodeDomProvider</code> by hitting a compile button. Then any issues or a message of success appears in the second textbox. If it's a success, you can hit the run button for it to run in a console window.</p>
  
  <p>What I would like to do is not have the compiled program run in a separate window.</p>
  
  <p>I've managed to figure out how to redirect the output to the second textbox, but I am having difficulty getting any input. I even made a third textbox with text put in beforehand to try to just get some sort of input in, but the form ends up freezing. You can see this in the code below.</p>
  
  <pre><code>private void runButton_Click(object sender, EventArgs e)
      {
          secondBox.Text = "";
  
          Process process = new Process();
          process.StartInfo.FileName = Program;
          process.StartInfo.RedirectStandardOutput = true;
          process.StartInfo.RedirectStandardError = true;
          process.StartInfo.RedirectStandardInput = true;
          process.StartInfo.CreateNoWindow = true;
          process.StartInfo.UseShellExecute = false;
          process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
          process.StartInfo.CreateNoWindow = true;
          process.Start();
  
          StreamReader reader = process.StandardOutput;
          StreamReader eReader = process.StandardError;
          StreamWriter writer = process.StandardInput;
  
          secondBox.Text += reader.ReadToEnd();
          secondBox.Text += eReader.ReadToEnd();
          writer.WriteLine(thirdBox.Text);
      }
  </code></pre>
  
  <p>(I know just adding in input and output one time isn't going to cut it for what I want to do, but I'm taking it one step at a time.)</p>
  
  <p>I tried doing like this example: <a href="https://stackoverflow.com/questions/2883993/redirect-console-input-and-output-to-a-textbox">Redirect console input and output to a textbox</a>.
  I nixed the <code>writer</code> bits, going with <code>process.StandardInput.WriteLine(thirdBox.Text);</code> instead, but that still didn't work.</p>
  
  <p>There is also a problem of errors being generated when trying to use something like <code>System.Console.ReadKey()</code> within the compiled program because the real process window is not actually created (<code>process.StartInfo.CreateNoWindow = true;</code>). I found this on the subject: <a href="https://stackoverflow.com/questions/15860337/c-cant-readkey-if-my-parent-is-a-window-application-and-it-is-redirecting-my">C#: can&#39;t ReadKey if my parent is a window application and it is redirecting my stdout</a>, but I am not sure what to understand from that other than possibly running it in another console window?</p>
  
  <p>I've found a lot of information on transferring console output (which helped me figure that out) but not so much with input. Some pointing in the right direction would be appreciated, either with the input from textbox or with another way to embed the compiled program. Thank you.</p>