microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.55k stars 823 forks source link

Console output from bash.exe and lxrun.exe is formatted incorrectly when run from within bash (or from cmd.exe inside bash) #2024

Closed CherryDT closed 6 years ago

CherryDT commented 7 years ago

I'm running build 15063.138.

Running bash.exe inside bash fails (see #2023). Its console output is however displayed incorrectly: it looks like it is interpreted as ANSI instead of Unicode ("spaces" between letters) and umlauts are omitted. The issue with the umlauts is probably connected to #2009, but even with the right codepage, the umlauts are not displayed correctly (see below).

image

I also discovered that trying to run lxrun in the same manner (which should just output its usage help) also results in weird formatting like that: image

Trying the same from xterm does not show spaces between letters, but has apparently still encoding issues. On top of that, the "Press any key to continue prompt" doesn't react on keys in xterm.

image

As mentioned above, the umlaut issue is probably from #2009, but even when changing the codepage to 65001 to 850 (as it should be on my computer) or 437, the output is wrong:

image

zadjii-msft commented 7 years ago

This does look like some sort of bug in passing the input through WSL back to cmd.exe. Do you happen to know of any other Windows programs that can repro this output behavior in bash (via interop)?

@adiviness for visibility, he did some buffer work for CU.

CherryDT commented 7 years ago

It happens also without cmd involved, when just running bash.exe from inside bash.

Until now I saw it only with bash.exe and lxrun.exe. I checked a few other commands and they work OK.

It looks as if WriteConsoleA were used in place of WriteConsoleW but it would make no sense that it then works in other conditions (such as normal cmd without bash involved, or xterm)...

mqudsi commented 7 years ago

It makes sense, bash.exe writes back to conhost in wide characters, subprocesses of bash write to the emulated tty in utf8. So you're seeing Unicode written back to the utf8 channel between bash and its subprocesses.

This happens with any app that uses WriteConsole instead of writing to the output in a manner that can be properly intercepted by WSL, no?

bitcrazed commented 6 years ago

This issue was moved to Microsoft/console#110