Python REPL doesn't work on Windows over remote powershell session (winrm)
Hello dears Python devs, I'm taking the initiative of writing to you for a question on Python REPL over Windows remote powershell session (winrm). As we’ve all known, Python REPL works well on local Linux, local Windows, and remote SSH session. But for the remote Windows powershell session the REPL doesn’t work, when I type ‘’python” on the remote session, there’s nothing happened. =================================== Steps to reproduce # 1/ pre-install python on server1 (server 1 is a windows os) # 2/ from a powershell console on server0, type below 2 commands: enter-pssession server1 python Expected behavior # The python >>> prompt appears Actual behavior # Nothing, it is still the powershell prompt =================================== The problem impacts all the python versions and all the windows versions. This make me (and other windows guys) unable to use Python remotely, especially for the Windows Server Core version, which is a headless version (no GUI, so no remote desktop connection), the only way to connect to them is by the remote powershell session. You can imagine the panic if Python REPL doesn’t work over SSH for Linux. Could you please kindly have a look, and tell at least why it doesn’t work ? Thanks. FYI, I’ve also opened a issue on Microsoft Powershell GitHub : https://github.com/PowerShell/PowerShell/issues/7581 Regards, Xiang ZHU
On Sun, Aug 26, 2018 at 9:09 AM, ZHU Xiang <xiang.zhu@outlook.com> wrote:
But for the remote Windows powershell session the REPL doesn’t work, when I type ‘’python” on the remote session, there’s nothing happened.
# 1/ pre-install python on server1 (server 1 is a windows os) # 2/ from a powershell console on server0, type below 2 commands: enter-pssession server1 python
Quick check: With the exact same servers, after you enter-possession, can you run a Python *script* successfully? And/or can you run: python -c "print(1+2)" ? If so, it's definitely just a REPL problem.
The problem impacts all the python versions and all the windows versions.
Which versions were tested? ChrisA
ZHU Xiang <xiang.zhu@outlook.com> writes:
=================================== Steps to reproduce
# 1/ pre-install python on server1 (server 1 is a windows os) # 2/ from a powershell console on server0, type below 2 commands: enter-pssession server1 python
Expected behavior # The python >>> prompt appears
Actual behavior # Nothing, it is still the powershell prompt ===================================
Still the powershell prompt or nothing at all? If the latter, try using "python -i" instead. The "-i" will force interactive mode if stdin isn't otherwise detected as interactive (under the covers, isatty() is false for stdin), which is where I believe the issue is. I've used that under Windows ssh sessions (though with cygwin rather than powershell as well as some of my own remoting tools) for as long as I can remember (certainly back to XP and Python 2.x - maybe 1.x) for an interactive prompt when operating without a local windows console. I'm not sure if there's any better way for Python to detect a remote shell as being interactive under Windows that would cover such cases. Perhaps some of the newer pty changes I read Microsoft is making might help, assuming it flows through to the isatty() test. -- David
On Sun, 26 Aug 2018 at 12:16, David Bolen <db3l.net@gmail.com> wrote:
I'm not sure if there's any better way for Python to detect a remote shell as being interactive under Windows that would cover such cases. Perhaps some of the newer pty changes I read Microsoft is making might help, assuming it flows through to the isatty() test.
Based on https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line..., that seems plausible to me, since they're adding a true pseudo-tty system, and mostly modeling it's behaviour on the *nix one. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On Sat, Aug 25, 2018 at 11:09:10PM +0000, ZHU Xiang wrote:
But for the remote Windows powershell session the REPL doesn’t work, when I type ‘’python” on the remote session, there’s nothing happened. [...] FYI, I’ve also opened a issue on Microsoft Powershell GitHub : https://github.com/PowerShell/PowerShell/issues/7581
If I have understood this correctly: https://github.com/PowerShell/PowerShell/issues/7295 and the explanation here: https://stackoverflow.com/questions/21466372/execution-of-interactive-comman... I think this is a limitation of Powershell, not Python. But I am not a Windows admin and don't really understand Powershell, so I could be wrong. -- Steve
participants (5)
-
Chris Angelico
-
David Bolen
-
Nick Coghlan
-
Steven D'Aprano
-
ZHU Xiang