title: C#: send ctrl+c to console program started with Process.Start()?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/283128/how-do-i-send-ctrlc-to-a-process-in-c">How do I send ctrl+c to a process in c#?</a>  </p>
  </blockquote>
  
  
  
  <p>I can't figure out how to simulate sending <kbd>Ctrl</kbd>+<kbd>C</kbd> to an external program. When I run the program manually through CMD, when I press <kbd>Ctrl</kbd>+<kbd>c</kbd> it will abort and ask me if I want to save before it shuts down completely. I'm trying to simulate this through C# but it doesn't seem to work.</p>
  
  <p>This is what I am doing now:</p>
  
  <pre><code>// Create new process object
  process = new Process();
  
  // Setup event handlers
  process.EnableRaisingEvents = true;
  process.OutputDataReceived += OutputDataReceivedEvent;
  process.ErrorDataReceived += ErrorDataReceivedEvent;
  process.Exited += ProgramExitedEvent;
  
  // Setup start info
  ProcessStartInfo psi = new ProcessStartInfo
  {
      FileName = ExePath,
      UseShellExecute = false, // Must be false to redirect IO
      RedirectStandardOutput = false,
      RedirectStandardError = false,
      RedirectStandardInput = true,
      Arguments = arguments
  };
  
  process.StartInfo = psi;
  
  // Start the program
  process.Start();
  
  process.StandardInput.Write( "\x3" ); // 0x3 is Ctrl+C according to ASCII table
  </code></pre>
  
  <p>The program doesn't respond to this and just continues. Is the problem that Windows actually doesn't send <kbd>Ctrl</kbd>+<kbd>C</kbd> to the input stream when doing <kbd>Ctrl</kbd>+<kbd>c</kbd> in the console, but instead sends an "interrupt" to the process? I thought that sending "\x3" to the input stream is EXACTLY what Windows does when one presses <kbd>Ctrl</kbd>+<kbd>c</kbd> in the console. Am I wrong?</p>