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

Closed
segin opened this Issue Aug 18, 2016 · 18 comments

Comments

Projects
None yet
8 participants
@segin

segin commented Aug 18, 2016

  • 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

@russalex russalex added the console label Aug 18, 2016

@bitcrazed

This comment has been minimized.

Show comment
Hide comment
@bitcrazed

bitcrazed Aug 18, 2016

Collaborator

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.

Collaborator

bitcrazed commented Aug 18, 2016

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.

@segin

This comment has been minimized.

Show comment
Hide comment
@segin

segin Aug 19, 2016

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 commented Aug 19, 2016

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.

@gaelcolas

This comment has been minimized.

Show comment
Hide comment
@gaelcolas

gaelcolas Aug 24, 2016

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

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

@zadjii-msft

This comment has been minimized.

Show comment
Hide comment
@zadjii-msft

zadjii-msft Aug 24, 2016

Member

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.

Member

zadjii-msft commented Aug 24, 2016

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.

@segin

This comment has been minimized.

Show comment
Hide comment
@segin

segin Aug 24, 2016

@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 commented Aug 24, 2016

@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.

@MaximoTrinidad

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Oct 2, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Oct 3, 2016

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 commented Oct 3, 2016

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!

@segin

This comment has been minimized.

Show comment
Hide comment
@segin

segin Oct 3, 2016

@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 commented Oct 3, 2016

@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 :)

@MaximoTrinidad

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Oct 3, 2016

@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!

@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!

@zadjii-msft

This comment has been minimized.

Show comment
Hide comment
@zadjii-msft

zadjii-msft Oct 3, 2016

Member

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.

Member

zadjii-msft commented Oct 3, 2016

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.

@MaximoTrinidad

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Oct 3, 2016

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!
:)

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

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Oct 3, 2016

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 commented Oct 3, 2016

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

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Oct 3, 2016

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

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

@zadjii-msft

This comment has been minimized.

Show comment
Hide comment
@zadjii-msft

zadjii-msft Feb 6, 2017

Member

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.

Member

zadjii-msft commented Feb 6, 2017

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.

@MaximoTrinidad

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Feb 6, 2017

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

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

@zadjii-msft

This comment has been minimized.

Show comment
Hide comment
@zadjii-msft

zadjii-msft Feb 6, 2017

Member

@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.

Member

zadjii-msft commented Feb 6, 2017

@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.

@MaximoTrinidad

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Feb 6, 2017

@zadjii-msft,

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

@zadjii-msft,

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

@MaximoTrinidad

This comment has been minimized.

Show comment
Hide comment
@MaximoTrinidad

MaximoTrinidad Feb 6, 2017

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment