WSL: Use of the script
utility for capturing colored output (with ANSI/VT escape sequences) breaks display formatting #20524
Open
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 reproduce
Note:
- The symptom is reminiscent of the problem described in Select-String doesn't render VT (ANSI) escape sequences in its for-display output with input from external programs on Windows #18294, which was inappropriately closed.
- However, unlike the latter, the symptom described here also affects running in Windows Terminal, not just
conhost.exe
console windows. - As in the latter issue, this is merely a display problem: it doesn't affect capturing or redirecting the output.
Write-Output
is used below for simplicity; a real-world use case would beTee-Object -Variable out
, where you want both to-display output and to capture the (unconditionally colored) output in a variable.
# From WSL (using a WSL-installed PowerShell version)
# Dummy command that is seemingly necessary to provoke the symptom *right away*.
# Without it, the code below must be run *twice* to surface the symptom.
/bin/echo | Write-Output
# !! Broken display output
script -qc 'ls --color=auto /mnt/c/windows' /dev/null | Write-Output
'----------------'
# OK, due to (...) enclosure
(script -qc 'ls --color=auto /mnt/c/windows' /dev/null) | Write-Output
Expected behavior
Both script
commands should properly relay the colored, columnnar ls
output.
Actual behavior
The first script
command's layout is broken.
Error details
No response
Environment data
PowerShell 7.3.8 on WSL (Ubuntu 20.04) on Windows 11 22H3
Visuals
Broken display output from the first command: