Skip to content

Select-String doesn't render VT (ANSI) escape sequences in its for-display output with input from external programs on Windows #18294

Closed

Description

Prerequisites

Steps to reproduce

This is a regression from 7.2.6 and only happens:

  • on Windows (not on macOS; haven't tried on Linux)
  • in regular console windows (conhost.exe), not in Windows Terminal
  • with input from external programs
cmd /c echo foo | sls f

Expected behavior

foo should print with f highlighted, to indicate what part of the line matched.

Actual behavior

←[7mf←[0moo

That is, the VT escape sequences are mistakenly rendered as verbatim characters.

Error details

No response

Environment data

PowerShell Core 7.3.0-preview.8 on Windows 10 21H2, Windows 11 22H2

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Oct 14, 2022
  2. changed the title [-]Select-String doesn't render VT (ANSI) escape sequences with input from external programs on Windows[/-] [+]Select-String doesn't render VT (ANSI) escape sequences in its for-display output with input from external programs on Windows[/+] on Oct 14, 2022
  3. SeeminglyScience commented on Oct 14, 2022

    @SeeminglyScience
    Contributor

    Interestingly I can't repro this on Windows 11. Can anyone else on 10 try?

    I would assume this has to do with console modes. Michael Klement (@mklement0) can you see if:

    $results = cmd /c echo foo | sls f
    $results

    has the same effect?

  4. mklement0 commented on Oct 14, 2022

    @mklement0
    ContributorAuthor

    Strange, Patrick Meinecke (@SeeminglyScience): I do see it in Windows 11 too, albeit only in conhost.exe windows, not in Windows Terminal - I've updated the initial post to clarify.

    Yes, (cmd /c echo foo | sls f) (the equivalent of your commands) makes the problem go away (the VT sequences then render as expected).

  5. SeeminglyScience commented on Oct 14, 2022

    @SeeminglyScience
    Contributor

    Strange, Patrick Meinecke (@SeeminglyScience): I do see it in Windows 11 too, albeit only in conhost.exe windows, not in Windows Terminal - I've updated the initial post to clarify.

    That's very interesting, FWIW I did try both conhost and WT and couldn't repro in either

  6. mklement0 commented on Oct 14, 2022

    @mklement0
    ContributorAuthor

    Mysterious (to recap: 7.3.0-preview.8, conhost.exe window, $PSStyle.OutputRendering at its default, 'Host', W10 21H2 and W11 22H2). Perhaps others can report what they get.

  7. SeeminglyScience commented on Oct 14, 2022

    @SeeminglyScience
    Contributor

    What's your build number for w11? I'm on 22621.674 (22H2 Oct 2022) (last bit only appears in winver it seems)

  8. mklement0 commented on Oct 14, 2022

    @mklement0
    ContributorAuthor

    2261.232 (I wouldn't expect it to make a difference, but for the record it is an ARM build running in a VMWare Fusion VM on an M1 Mac; however, the Windows 10 VM runs on an Intel Mac).

  9. SteveL-MSFT commented on Oct 17, 2022

    @SteveL-MSFT
    Member

    I'm able to repro this. However, I think it's a problem with conhost:

    $psstyle.outputrendering = 'ansi'
    cmd /c echo foo | sls f
    cmd /c echo foo | sls f > out.txt
    cat out.txt

    image

    It appears that the right sequence is emitted, but conhost isn't rendering it.

  10. added
    Resolution-External
    and removed
    Needs-Triage
    on Oct 17, 2022
  11. mklement0 commented on Oct 17, 2022

    @mklement0
    ContributorAuthor

    Steve Lee (@SteveL-MSFT), glad to hear that you see it too, but note that it probably isn't conhost.exe, given that the same command works fine in v7.2.6 - or do you see the symptom there too?

  12. SeeminglyScience commented on Oct 17, 2022

    @SeeminglyScience
    Contributor

    I would guess it's related to #16612 but I've looked it over and I can't easily see how. We should be re-enabling VT more often rather than less, so something is a little off for sure. /cc Dongbo Wang (@daxian-dbw)

  13. ghost closed this as completedon Oct 18, 2022
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

    Resolution-External

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions