title: C# ReadKey crashing console app when called using <nul
body: <p>So I decided to start programming in C#, and one of the things I did was to create a "pausec.exe" (a pause.exe clone). It works, but when calling it like:  </p>
  
  <pre><code>&lt; nul pausec  
  </code></pre>
  
  <p>...it crashes. The error I get - translated from Spanish to the best of my knowledge - goes like this:</p>
  
  <blockquote>
    <p>Unhandled exception: System.InvalidOperationException: Can't read
    keys when any of the applications doesn't have a console or when the
    console input has been redirected from a file. Try with Console.Read.</p>
  </blockquote>
  
  <p>And the stacktrace telling me where the error is:  </p>
  
  <pre><code> in System.Console.ReadKey(Boolean intercept)  
   in System.Console.ReadKey()  
   in pausec.Program.Main(String[] args)
  </code></pre>
  
  <p>This is the code I'm running:</p>
  
  <pre><code>using System;
  
  namespace pausec
  {
      class Program
      {
          static void Main(string[] args)
          {
              Console.Write("Press any key to continue . . . ");
              Console.ReadKey(true);
              Console.Write("\n");
          }
      }
  }
  </code></pre>
  
  <p>I'm wondering if there's a workaround for this, maybe even a way to ignore the <code>ReadKey</code> when using <code>&lt; nul</code>?</p>
  
  <p>Any help is appreciated.<br>
  Thanks in advance</p>
  
  <p><strong>UPDATE</strong>: Found a way, by removing the intercept (<a href="https://stackoverflow.com/a/19939864/702048">as Alberto Solano suggested</a>) and then, adding <code>Console.Write("\b \b");</code>
  after the <code>ReadKey</code> method, it works. Weird thing is, when I copy the application to my desktop, it doesn't wait for user input and closes automatically.</p>
  
  <p><strong>UPDATE 2</strong>: It works perfectly now. Thank you all for answering!</p>