title: Win32 - read from stdin with timeout
body: <p>I'm trying to do something which I think should be simple: do a blocking read from standard input, but timing out after a specified interval if no data is available.</p>
  
  <p>In the Unix world this would be simple with <code>select()</code> but that doesn't work in Windows because <code>stdin</code> isn't a socket. What's the next simplest option without creating extra threads etc?</p>
  
  <p>I'm using visual C++ targeting a Win32 environment.</p>
  
  <p>so far I have tried:</p>
  
  <ol>
  <li><p>using <code>select</code> (doesn't work if the input is not a socket)</p></li>
  <li><p>using <code>WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE))</code>. - Remy's first suggestion. This always seems to return immediately when you call it if the standard input is a console (others have reported the same problem)</p></li>
  <li><p>using overlapped IO and doing a <code>WaitForSingleObject</code> (Remy's third suggestion). In this case the read always seems to block when the input is coming from a console - it seems that <code>stdin</code> does not support asynchronous I/O.</p></li>
  </ol>
  
  <p>At the moment I'm thinking my only remaining option is to create a thread which will do a blocking read and then signal an event, and then have another thread which waits for the event with a timeout.</p>