Home > Software design >  How to make Paramiko use Powershell by default?
How to make Paramiko use Powershell by default?

Time:06-08

I'm SSHing to a Windows machine with Paramiko and I'm stressed out by how hard it is to write a command because:

  • exec_command runs in cmd prompt console, which has limited functionality so I need powershell, meaning I should prefix the command with pwsh -c "the command"
  • However, cmd prompt doesn't support multi-line nor multiple commands naturally, so I need to stick in caret ^s and &&s in the command.
  • Inside the command I'm calling Python with python -c 'print("hello")\nprint("world")', however I'm aready using " for pwsh -c "the command" meaning I need to escape it with backticks `".

This is fiendishly complex and ugly, the code is a mess, its python and powershell and cmd prompt special characters intertwined at once. I'm almost 100% sure I'm misssing something and there is an easier way to do it hence I'm asking whether Paramiko can run do exec_command in powershell by default.

CodePudding user response:

The client (Paramiko) has no control over how the command is interpreted. It's about the server.

Windows Win32-OpenSSH definitely can use PowerShell as the default shell.

  • Related