title: Console input redirect
body: <p>I am writing a windows application that emulates the console by redirecting input and output of the cmd.exe to a text box. The starting code is below:</p>
  
  <pre><code>StreamWriter inputWriter;
  StreamReader outputReader;
  StreamReader errorReader;
  Process proc = new Process();
  byte[] outputBuffer = new byte[1024];
  byte[] errorBuffer = new byte[1024];
  
  proc.StartInfo.FileName = "cmd.exe";
  proc.StartInfo.FileName = "cmd.exe";
  proc.StartInfo.Arguments = "/Q";
  proc.StartInfo.UseShellExecute = false;
  proc.StartInfo.ErrorDialog = false;
  proc.StartInfo.RedirectStandardError = true;
  proc.StartInfo.RedirectStandardInput = true;
  proc.StartInfo.RedirectStandardOutput = true;
  proc.StartInfo.CreateNoWindow = true;
  proc.Start();
  inputWriter = proc.StandardInput;
  outputReader = proc.StandardOutput;
  errorReader = proc.StandardError;
  outputReader.BaseStream.BeginRead(outputBuffer, 0, outputBuffer.Length, ShowOutput, null);
  errorReader.BaseStream.BeginRead(errorBuffer, 0, errorBuffer.Length, ShowError, null);proc.StartInfo.Arguments = "/Q";
  proc.StartInfo.UseShellExecute = false;
  proc.StartInfo.ErrorDialog = false;
  proc.StartInfo.RedirectStandardError = true;
  proc.StartInfo.RedirectStandardInput = true;
  proc.StartInfo.RedirectStandardOutput = true;
  proc.StartInfo.CreateNoWindow = true;
  proc.Start();
  inputWriter = proc.StandardInput;
  outputReader = proc.StandardOutput;
  errorReader = proc.StandardError;
  outputReader.BaseStream.BeginRead(outputBuffer, 0, outputBuffer.Length, ShowOutput, null);
  errorReader.BaseStream.BeginRead(errorBuffer, 0, errorBuffer.Length, ShowError, null);
  </code></pre>
  
  <p>When I start the proces I am able to read the console output and also to send the commands to it by writing to the input stream.</p>
  
  <p>When I start some application this way the output of that application is also being redirected and everything still works fine, but the application doesn't seem to receive the data that is being written to the input stream. Even some console commands can't receive the input.
  e.g. If i call <code>inputWriter.WriteLine("del *.log");</code> I receive the "Are you sure" prompt but when i call <code>inputWriter.Write("y");</code> "y" is echoed back by the console but nothing happens, the console continues to wait for input.
  If i call <code>inputWriter.WriteLine("pause");</code> console pauses and after <code>inputWriter.Write(" ");</code> it continues just like it should.</p>
  
  <p>What is the problem here and how can I correctly redirect the input to both the console and the application (and command) that is being executed within it?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Cheers!</p>