Home All Groups Group Topic Archive Search About

Detecting redirection of standard ports

Author
13 Jan 2005 5:45 PM
PIEBALD
I often write console programs that need to detect when stdin and stdout are
redirected.

I found out how to detect this for stdin by using API calls GetStdHandle()
and PeekConsoleInput() (from a Dr. GUI article).

But I still need to detect such for stdout, is there a way?

And shouldn't this be a property of the standard streams?

Author
14 Jan 2005 5:53 AM
Henry Jia
How about use the Console class?

Show quote
"PIEBALD" <PIEB***@discussions.microsoft.com> wrote in message
news:CB5746A3-0CD1-4377-B7CE-8B7930F16ED1@microsoft.com...
> I often write console programs that need to detect when stdin and stdout
are
> redirected.
>
> I found out how to detect this for stdin by using API calls GetStdHandle()
> and PeekConsoleInput() (from a Dr. GUI article).
>
> But I still need to detect such for stdout, is there a way?
>
> And shouldn't this be a property of the standard streams?
Author
14 Jan 2005 3:27 PM
PIEBALD
Well, of course I'm using the Console class, but it has no built-in detection
for redirection. It allows one to redirect, but won't tell you whether or not
it's _already_ redirected.
Author
24 Jan 2005 9:01 PM
PIEBALD
No one has any ideas?

AddThis Social Bookmark Button