Skip to content

Commit

Permalink
Fix encoding errors on Windows guests (fixes: #156)
Browse files Browse the repository at this point in the history
On Windows guests the default encoding will be set to whatever
default legacy encoding, not utf-8. This issue isn't apparent on English locale
Windows guests, as there the encodings (ISO-8859-1, utf-8) happen to coincide.

However, on e.g. German Windows guests this will cause an encoding error when
reading any output from there.

This patch ensures that the proper encoding is set on every command.
  • Loading branch information
Lee Garrett authored and csmart committed Sep 19, 2023
1 parent da2cd29 commit eebee53
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/connection/libvirt_qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def exec_command(self, cmd, in_data=None, sudoable=True):
# prompt that will not occur
sudoable = False

# Make sure our first command is to set the console encoding to
# utf-8, this must be done via chcp to get utf-8 (65001)
cmd = ' '.join(["chcp.com", "65001", self._shell._SHELL_REDIRECT_ALLNULL, self._shell._SHELL_AND, cmd])

# Generate powershell commands
cmd_args_list = self._shell._encode_script(cmd, as_list=True, strict_mode=False, preserve_rc=False)

Expand Down

0 comments on commit eebee53

Please sign in to comment.