Skip to content

Using Console.SetOut doesn't affect IsOutputRedirected #17959

Closed

Description

@BrennanConroy

... similarly for Input and Error.

See : https://github.com/dotnet/corefx/blob/5e36ca02d2594f715da829aafaf7af2b554dfcdf/src/System.Console/src/System/ConsolePal.Unix.cs#L461-L467

The summary describes the behavior I expect which is checking Console.Out but the actual behavior is checking STDOUT

@stephentoub @ianhays

Activity

  1. ianhays commented on Jul 29, 2016

    @ianhays
    Contributor

    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.

  2. BrennanConroy commented on Jul 29, 2016

    @BrennanConroy
    MemberAuthor

    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

  3. muratg commented on Aug 2, 2016

    @muratg

    👀

  4. removed their assignment
    on Oct 25, 2016
  5. karelz commented on Nov 3, 2016

    @karelz
    Member

    We need formal API proposal.

  6. ianhays commented on Dec 19, 2016

    @ianhays
    Contributor

    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.

  7. muratg commented on Dec 19, 2016

    @muratg

    @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...

  8. BrennanConroy commented on Dec 20, 2016

    @BrennanConroy
    MemberAuthor

    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

  9. glennc commented on Jan 6, 2017

    @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.

  10. transferred this issue fromdotnet/corefxon Jan 31, 2020
  11. added this to the 2.0.0 milestone on Jan 31, 2020
  12. ghost locked as resolved and limited conversation to collaborators on Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-needs-workarea-System.Consolehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions