Testing whether StdIn and StdOut have been redirected

Within a Win32 application compiled by FreePascal for the Win32 target,
how can I test:

- whether the Standard Input (StdIn) device is coming from the keyboard
  (default) or has been redirected from a file or other device (via the
   "<" command-line operator, for example)?

- whether the Standard Output (StdOut) device is going to the display
  (default) or had been redirected to a file or other device (via the
   ">" command-line operator, for example)?

I need to know so that if the devices are keyboard and display I can ask
the user a question and expect him to type the answer, but if they are
redirected then it must be a batch operation and I should not do that.

Please post reply to the newsgroup.  If you prefer to send e-mail,
please remove the "nospam." from my address.

     - Rich