2

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 already 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, it's Python and PowerShell and cmd prompt special characters intertwined at once. I'm almost 100% sure I'm missing 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.

1
  • 1
    Technically, nested double quotes would require escaping for cmd.exe to pass, which means those should be escaped using backward slashes, i.e. pwsh -c "python -c 'print(\"hello\")\nprint(\"world\")'". Commented Jun 6, 2022 at 22:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Microsoft should just cull cmd, its simply lame and vastly inferior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.