You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using Console.SetOut doesn't affect IsOutputRedirected #17959
IsOutputRedirected looks at the output/input/error handles themselves. SetOut doesn't affect those, so Is*Redirected is unaffected by SetOut/SetIn/SetError. SetOut only modifies the TextWriter that the Console operations call e.g. if you do a manual interop write to the stdout handle it will function the same regardless of what SetOut is set to.
The Unix behavior was made to mimic the Windows behavior in this regard.
Yeah I can see that. I'm saying its not great behavior, you are operating on the "Console" object when calling SetOut and IsOutputRedirected should reflect the "Console" objects internal state.
It would be great to have a way of seeing if Console.Out (and friends) is actually redirected from STDOUT without having to manually Pinvoke
Does anyone want to take this and submit a formal API proposal with samples and use cases? If not, I'm going to close the issue as there hasn't been any movement in a while.
We wanted a way to check if Console.Out was being redirected for logging to possibly remove ANSI Color Codes. I'm not sure if we still want to be able to do that @glennc
I think we are good to close this. At this point we have enough other mitigations to the root problems in place that it isn't important enough for us to try and make a change at this level of the stack.
Activity
ianhays commentedon Jul 29, 2016
IsOutputRedirected looks at the output/input/error handles themselves. SetOut doesn't affect those, so Is*Redirected is unaffected by SetOut/SetIn/SetError. SetOut only modifies the TextWriter that the Console operations call e.g. if you do a manual interop write to the stdout handle it will function the same regardless of what SetOut is set to.
The Unix behavior was made to mimic the Windows behavior in this regard.
BrennanConroy commentedon Jul 29, 2016
Yeah I can see that. I'm saying its not great behavior, you are operating on the "Console" object when calling
SetOutandIsOutputRedirectedshould reflect the "Console" objects internal state.It would be great to have a way of seeing if
Console.Out(and friends) is actually redirected fromSTDOUTwithout having to manually Pinvokemuratg commentedon Aug 2, 2016
👀
karelz commentedon Nov 3, 2016
We need formal API proposal.
ianhays commentedon Dec 19, 2016
Does anyone want to take this and submit a formal API proposal with samples and use cases? If not, I'm going to close the issue as there hasn't been any movement in a while.
muratg commentedon Dec 19, 2016
@BrennanConroy could you update the impact of this? (and what workaround did we use?)
@ianhays please do not close just yet. IIRC, an ASP.NET scenario was impacted with this...
BrennanConroy commentedon Dec 20, 2016
We wanted a way to check if
Console.Outwas being redirected for logging to possibly remove ANSI Color Codes. I'm not sure if we still want to be able to do that @glenncglennc commentedon Jan 6, 2017
I think we are good to close this. At this point we have enough other mitigations to the root problems in place that it isn't important enough for us to try and make a change at this level of the stack.