Title: Redirection of external command output breaks ANSI sequences · Issue #16775 · PowerShell/PowerShell · GitHub
Open Graph Title: Redirection of external command output breaks ANSI sequences · Issue #16775 · PowerShell/PowerShell
X Title: Redirection of external command output breaks ANSI sequences · Issue #16775 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/16775
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Redirection of external command output breaks ANSI sequences","articleBody":"### Prerequisites\n\n- [X] Write a descriptive title.\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [X] Search the existing issues.\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\n* Have Git for Windows installed\r\n* Run Powershell 7.21 (either in ConHost or the new Terminal app, bug is reproducible in both)\r\n* Create the following simple function:\r\n```\r\nfunction Test-Ansi {\r\n $VerbosePreference = 'Continue'\r\n Write-Verbose '------ Before ------'\r\n \u0026 \"$Env:ProgramFiles\\Git\\usr\\bin\\patch.exe\" --help \u003e $null\r\n Write-Verbose '------ After ------'\r\n}\r\n```\r\n* Observe properly formatted coloring for the line before\r\n* Observe line after being uncolored and ANSI sequences instead printed verbatim\r\n\r\n# Additional Notes\r\n\r\nThis behaviour was only observed in PowerShell 7 - running the same function on PowerShell 5 yields the expected behaviour with no breaking changes to the ANSI output. \r\n\r\nIt also doesn't make a difference whether the redirection is done via `| Out-Null` or doing a `$null` assignment. Even just redirecting stderr via `2\u003e$null` triggers the issue. _Not_ redirecting the command is the only way to have it run without breaking.\r\n\r\nThe issue also occurs independent of invocation, `Invoke-Expression` results in this bug as does using `Start-Command`.\r\n\r\nAlso running this slightly tweaked function:\r\n```\r\nfunction Test-Ansi-Async {\r\n $VerbosePreference = 'Continue'\r\n Write-Verbose '------ Before ------'\r\n Start-Process -FilePath \"C:\\Program Files\\Git\\usr\\bin\\patch.exe\" -RedirectStandardOutput NUL -ArgumentList '--help' -NoNewWindow\r\n Write-Verbose '------ After ------'\r\n}\r\n```\r\nwill yield different bugs in ConHost or Windows Terminal:\r\n\r\n* In ConHost browsing through command history will have corrupted output, with characters remaining on screen between history items\r\n* In Windows Terminal the ANSI color codes of the next command will be corruped\r\n\r\n(See screenshots for each case).\r\n\r\nIn both cases pressing \"Enter\" without any input restores proper output at the prompt.\n\n### Expected behavior\n\n```console\nVERBOSE: ------ Before ------\r\nVERBOSE: ------ After ------\n```\n\n\n### Actual behavior\n\n```console\nVERBOSE: ------ Before ------\r\n←[33;1mVERBOSE: ------ After ------←[0m\n```\n\n\n### Error details\n\n```console\nPS C:\\Windows\\System32› Get-Error\r\nPS C:\\Windows\\System32›\n```\n\n\n### Environment data\n\n```powershell\nName Value\r\n---- -----\r\nPSVersion 7.2.1\r\nPSEdition Core\r\nGitCommitId 7.2.1\r\nOS Microsoft Windows 10.0.22000\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\n```\n\n\n### Visuals\n\n# Visual Corruption in ConHost\r\n\r\n\r\n\r\n# Broken ANSI Codes in Windows Terminal\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/PatTheMav","@type":"Person","name":"PatTheMav"},"datePublished":"2022-01-20T01:40:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/16775/PowerShell/issues/16775"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:94ecc7a8-1b7f-aa2c-d5be-d90ce096f5ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B7C8:378B6C:2F4368:3F499F:6A51BD82 |
| html-safe-nonce | 5cb26b14a306a0673f19d57b6111162cdaa8f40656c5cca76251e59740b0f0c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCN0M4OjM3OEI2QzoyRjQzNjg6M0Y0OTlGOjZBNTFCRDgyIiwidmlzaXRvcl9pZCI6IjgyNzE2NDcyNzYyODU0MTA2OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 70e7176d738b0bc038ba4e9a5ad0aa7ae4025fd92f9aa0617640e2505da07f76 |
| hovercard-subject-tag | issue:1108738750 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/16775/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9b4f8016de5408b7b54bf23e36da39f53b995c9c4438dca06f9ada70d6d10e75/PowerShell/PowerShell/issues/16775 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9b4f8016de5408b7b54bf23e36da39f53b995c9c4438dca06f9ada70d6d10e75/PowerShell/PowerShell/issues/16775 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PatTheMav |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width