title: How to check if the program is run from a console?
body: <p>I'm writing an application which dumps some diagnostics to the standard output.</p>
  
  <p>I'd like to have the application work this way:</p>
  
  <ul>
  <li>If it is run from a standalone command prompt (via <code>cmd.exe</code>) or has standard output redirected/piped to a file, exit cleanly as soon as it finished,</li>
  <li>Otherwise (if it is run from a window and the console window is spawned automagically), then 
  additionally wait for a keypress before exiting (to let the user read the diagnostics) before the window disappears</li>
  </ul>
  
  <p>How do I make that distinction? <em>I suspect that examining the parent process could be a way but I'm not really into WinAPI, hence the question.</em></p>
  
  <p>I'm on MinGW GCC.</p>