title: standardinput not being redirected C#
body: <p>So I have a process (java commandline application) that is hidden with the output and input being redirected. I can read the output very easily and that works, but when I send a command it dosen't work.</p>
  
  <p>I think that I have determined that the input is not being redirected because:</p>
  
  <p>(A) When I send <code>WriteLine(//command here); Flush</code> no command is acknowledged by the program</p>
  
  <p>(B) When I unhide the cmd window (<code>StartInfo.CreateNoWindow = false;</code>) I can enter commands and run them (in the cmd window) even though the StandardInput is being redirected (<code>StartInfo.RedirectStandardInput = true;</code>)</p>
  
  <p>Here is the code:</p>
  
  <pre><code>namespace bukkit
  {
      public partial class Form1 : Form
  {
      private static StringBuilder _txt = new StringBuilder();
      private static bool _scrolled = false;
      Process mncrft = new Process();
  
      public Form1()
      {
          InitializeComponent();
  
          mncrft.StartInfo.WorkingDirectory = Path.GetTempPath();
          mncrft.StartInfo.Arguments = "-Xmx512M -Xms512M -jar C:\\mncrft\\mncrft.jar";
          mncrft.StartInfo.FileName = "java.exe";
          mncrft.StartInfo.UseShellExecute = false;
          mncrft.StartInfo.RedirectStandardOutput = true;
          mncrft.StartInfo.RedirectStandardError = true;
          mncrft.StartInfo.RedirectStandardInput = true;
          mncrft.StartInfo.CreateNoWindow = false;
          mncrft.ErrorDataReceived += build_ErrorDataReceived;
          //mncrft.OutputDataReceived += build_ErrorDataReceived;
          mncrft.EnableRaisingEvents = true;
          //mncrft.StandardInput.NewLine = "\r\n";
          mncrft.Start();
          mncrft.BeginOutputReadLine();
          mncrft.BeginErrorReadLine();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          _txt.AppendLine("Starting Minecraft...");
      }
  
      private void Form1_Close(object sender, EventArgs e)
      {
          mncrft.Close();
      }
  
      static void build_ErrorDataReceived(object sender, DataReceivedEventArgs e)
      {
          string msg = e.Data;
          if (msg != null &amp;&amp; msg.Length &gt; 0)
          {
              _txt.AppendLine(msg);
              _scrolled = false;
          }
      }
  
      private void mainTimer_Tick(object sender, EventArgs e)
      {
          if (_txt.Length &gt; 0)
          {
              txtOutput.Text = _txt.ToString();
  
              // scroll down
              if (_scrolled == false)
              {
                  txtOutput.SelectionStart = txtOutput.Text.Length;
                  txtOutput.ScrollToCaret();
                  _scrolled = true;
              }
          }
      }
  
      private void Execute_Click(object sender, EventArgs e)
      {
          if (textBox1.Text.Length &gt; 0)
          {
              mncrft.StandardInput.WriteLine(textBox1.Text);
              mncrft.StandardInput.Flush();
          }
      }
  }
  }
  </code></pre>
  
  <p>How can I redirect the input so that I can send commands?</p>
  
  <p>Thanks,
  Adam</p>
  
  <p>P.S: If this is confusing, just put a comment down and I will gladly clarify.</p>
  
  <p><strong>Answered</strong></p>
  
  <p>Thanks to Tim,
  Replace the following lines:</p>
  
  <pre><code>mncrft.StartInfo.FileName = "java.exe";
  mncrft.StartInfo.Arguments = "-Xmx512M -Xms512M -jar C:\\mncrft\\mncrft.jar";
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>mncrft.StartInfo.FileName = "java";
  mncrft.StartInfo.Arguments = "-Xmx512M -Xms512M -jar C:\\mncrft\\bukkit.jar -nojline";
  </code></pre>