Skip to content

Commit

Permalink
Use UTF-8 codepage in pywinrm shells
Browse files Browse the repository at this point in the history
This change opens a shell with the 65001 codepage, ensuring raw string
responses are UTF-8 encoded.

Fixes #6034.
  • Loading branch information
Stealthii committed Oct 18, 2023
1 parent a5c2f73 commit 563bca0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions contrib/runners/winrm_runner/winrm_runner/winrm_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,18 @@ def _winrm_get_command_output(self, protocol, shell_id, command_id):
return b"".join(stdout_buffer), b"".join(stderr_buffer), return_code

def _winrm_run_cmd(self, session, command, args=(), env=None, cwd=None):
# NOTE: this is copied from pywinrm because it doesn't support
# passing env and working_directory from the Session.run_cmd.
# It also doesn't support timeouts. All of these things have been
# added
shell_id = session.protocol.open_shell(env_vars=env, working_directory=cwd)
"""Run a command on the remote host and return the standard output and
error as a tuple.
Extended from pywinrm to support passing env and cwd to open_shell,
as well as enforcing the UTF-8 codepage. Also supports timeouts.
"""
shell_id = session.protocol.open_shell(
working_directory=cwd,
env_vars=env,
codepage=65001,
)
command_id = session.protocol.run_command(shell_id, command, args)
# try/catch is for custom timeout handing (StackStorm custom)
try:
Expand Down

0 comments on commit 563bca0

Please sign in to comment.