WSL icon indicating copy to clipboard operation
WSL copied to clipboard

PowerShell for Linux doesn't work well with the VT100 emulation of Console Host.

Open segin opened this issue 10 years ago • 18 comments

  • A brief description

Typing in commands, running them, error prompts, etc, basically any interaction causes the console output to be scrambled.

  • Expected results

As shown in this xterm window running in WSL and using VcXsrv as the X server: image

  • Actual results (with terminal output if applicable)

image

  • Your Windows build number

Build 14393.67

  • Steps / commands required to reproduce the error
  1. Download and install PowerShell for Linux under WSL using the .deb package provided on the PowerShell GitHub page
  2. Try to use PowerShell within the WSL environment using the Console Host as the terminal emulator (i.e. by simply using the console window provided by bash.exe/conhost.exe)
  • Strace of the failing command

Not provided as it's likely not useful or relevant

  • Required packages and commands to install

Listed here

segin avatar Aug 18 '16 20:08 segin

Thanks for reporting. I eagerly installed & started PowerShell on Bash/WSL this morning but found much the same as you report. We'll dig into this and figure out what's what.

bitcrazed avatar Aug 18 '16 21:08 bitcrazed

There's several workarounds I can recommend to users that wish to use PowerShell under WSL:

  1. Use a terminal multiplexing program like tmux or screen This works for the most part, as shown: image
  2. Use an X-based terminal emulator. Install xterm via sudo apt install xterm, install VcXsrv from https://sourceforge.net/projects/vcxsrv/files/vcxsrv/1.18.3.0/vcxsrv-64.1.18.3.0.installer.exe/download, and run xterm as xterm -display localhost:0.
  3. Use an SSH server (sudo apt-get openssh-server ; sudo /etc/init.d/ssh start) and connect to localhost via PuTTY or BitVise.

And as I've been a bit aggressive with @bitcrazed on Twitter about, perhaps instead of trying to emulate an existing $TERM type, perhaps it's a better idea to create a termcap and/or terminfo entry for ConHost, although that would require the cooperation of the team that's working on the Console Host, and thus possibly not feasible, but it would fix some things in the short term.

segin avatar Aug 19 '16 04:08 segin

I had the same problem, and found an MSDN article that shows how to use Tmux: https://blogs.msdn.microsoft.com/commandline/2016/06/08/tmux-support-arrives-for-bash-on-ubuntu-on-windows/ In short: Start bash, then execute tmux, then finally start powershell. powershell_on_ubuntu_on_windows

gaelcolas avatar Aug 24 '16 14:08 gaelcolas

I'm gonna personally recommend @segin's first option, using powershell within tmux on conhost seems to fix it. I'm trying to understand why exactly that is - there doesn't seem to be anything that's wrong in our (conhost.exe's) handling of the escape sequences powershell is sending us, but they do seem to be sending us sequences that cause the strangeness, and only without tmux as a wrapper. So I'll dig around in their code and see if I can't figure it out.

zadjii-msft avatar Aug 24 '16 21:08 zadjii-msft

@zadjii-msft - It's because 'tmux' is itself a terminal emulator. Thus, it's interpreting the escape sequences from programs attached to it's own sub-terminals, processing them internally, and then creating a brand new set of escape sequences to pass to the real terminal to display the internal representation.

In this case, you could think of it as a translating proxy :)

If I had to guess, part of the problem lies in PowerShell (or, more accurately, the .NET Core's Linux port.) It doesn't seem to be properly using termcap and/or terminfo to generate the proper escape sequences for the $TERM type indicated by environment variable.

segin avatar Aug 24 '16 22:08 segin

Hum! So, we have a workaround using xterm. But I haven't seen any mention of this been worked on since August 24th. I seen strong benefit in having WSL Bash working with PowerShell Open Source.

Any idea if this is going to be corrected?

Thx

MaximoTrinidad avatar Oct 02 '16 15:10 MaximoTrinidad

Thanks for the information provided here. I did test and more research and I'm happy to say that at least the workaround (using either of screen and xterm application) works.

Of course, the PowerShell cmdlet Clear-Host nor Linux 'clear' command won't work but I can use PowerShell in Bash for Windows.

I just blogged about it. If anyone care to check it out: [http://www.maxtblog.com/2016/10/running-powershell-in-windows-10-bash-workaround/]

This is Awesome!

MaximoTrinidad avatar Oct 03 '16 02:10 MaximoTrinidad

@MaximoTrinidad - Please keep in mind that you can also use tmux as well, which does not require elevated privileges, that is, does not require being run as 'root'.

This may be of value if you are using openssh-server to provide shell access for collaborative development or exploration of WSL and wish to use the traditional Linux security model for Linux user separation.

If any of my suggestions have helped you, I'd not mind a little shout-out in your blog post :)

segin avatar Oct 03 '16 09:10 segin

@segin This is Great! I already been using "Xserver for Windows" for some time and recently using 'screen' on my Linux box. I just needed to know about 'xterm' then try them in Bash for Windows. I already know to look for the configuration file could help in clearing some issues. So I found more information on the internet to get what I wanted. I did update my blog and added the links I use for the workaround.

I love this community!

MaximoTrinidad avatar Oct 03 '16 13:10 MaximoTrinidad

So, just to follow up with everyone:

I have been investigating this for a little while now, and the problem isn't with conhost.exe or powershell itself. That being said, I'm not really sure what the problem is yet, but it goes all the way down to dotnet core's implementation of System.Console.GetCursor{Top/Left}, and it's interaction with LXCore/bash.exe.

I believe (but can't prove yet unfortunately) that this is also related to some problems with other applications as well, so this is my highest priority at the moment.

Until then, I agree with @segin's recommendation to use tmux, which somehow avoids this problem.

zadjii-msft avatar Oct 03 '16 15:10 zadjii-msft

Awesome! I'm kind of like using 'screen' as I don't need to use xserver to open an external terminal. It comes down to user choice. That's why I blogged about both of them and discover how to configure xterm to use the mouse scroll bar. I love this hacking techniques!

And, most important! I finally can use PowerShell in Bash for Windows.

Hum! I realized that I haven't use tmux. I'll give it a try.

Thanks everyone! :)

MaximoTrinidad avatar Oct 03 '16 16:10 MaximoTrinidad

Ah! I just tested tmux and doesn't work for me. I'm expecting to be able to scroll up and down in PowerShell after starting the application. So, I'm guessing there's another set of ctrl keys or a configuration file to make it work.

For now, I'm comfortable using either 'screen' or 'xterm' application.
I won't give up with tmux!

MaximoTrinidad avatar Oct 03 '16 16:10 MaximoTrinidad

Thanks @segin !!
I got the cheat sheet for tmux: https://tmuxcheatsheet.com/. Now , I understand and I'm now liking it

I will build a short blog soon about it.

Sample image using Crtl-B + pgUp:

tmuxsampleup_2016-10-03

MaximoTrinidad avatar Oct 03 '16 16:10 MaximoTrinidad

Status Update: I made a change to the lxss kernel last friday that should make input sequences that are generated by a single keypress all get injected into the subsystem at the same time, as opposed to character by character. This was in response to a number of issues, #425, #933, #980, and a reported issue with ghci.

Ideally, this should be fixed in an insiders build soontm.

I don't think it fixes everything with Powershell on WSL (they still repaint the entire line on any input, and that can cause some blinking/cursor jumping), but it should be at least usable now.

zadjii-msft avatar Feb 06 '17 16:02 zadjii-msft

Just recently, recently I finally got PowerShell working in WSL. But is thanks to installing Ubuntu Desktop. I blogged about it, and seems to work: http://www.maxtblog.com/2017/01/windows-10-bash-and-powershell-redux/

So, now that I got it to work, I haven't try using both 'screen' or 'xterm' in the Ubuntu Desktop environment. (see image below)

One thing, the 'screen' app in WSL is not working correctly. The screen welcome page doesn't come up and the it resize the console prompt. I will create an incident about it today!

powershell_works_2017-01-20_16-35-28

MaximoTrinidad avatar Feb 06 '17 16:02 MaximoTrinidad

@MaximoTrinidad Oh, that part about screen resizing the window should also be fixed in insiders, don't you worry. I believe that change also fixed the startup page as well.

zadjii-msft avatar Feb 06 '17 17:02 zadjii-msft

@zadjii-msft,

Ah! I posted the issue.  No worries! Have some one closed the incident if is already resolved. Sorry!! :)

MaximoTrinidad avatar Feb 06 '17 17:02 MaximoTrinidad

Hi @zadjii-msft

BTW, all my issues with PowerShell has been corrected by using 'Ubuntu Desktop'. I can even use both 'screen' and xterm app to run PowerShell.

screenfix_03_2017-02-06_11-59-11

MaximoTrinidad avatar Feb 06 '17 17:02 MaximoTrinidad