Update winrm-exec.py - #97
Conversation
GrymnDolen
commented
Sep 14, 2023
There was a problem hiding this comment.
Pull request overview
This PR adjusts winrm-exec.py stdout/locale configuration and modifies how command output is decoded/written, aiming to improve special-character handling and Windows console compatibility.
Changes:
- Adds locale and stdout encoding configuration at import time.
- Introduces a hard-coded
cp437decoding path when streaming command output. - Minor refactor/formatting in the output read loop (variable spacing, extra error handling).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| sys.stdout.reconfigure(encoding='utf-8') | ||
| locale.setlocale(locale.LC_ALL, 'fr_FR.utf8') |
| import codecs | ||
|
|
||
| sys.stdout.reconfigure(encoding='utf-8') | ||
| locale.setlocale(locale.LC_ALL, 'fr_FR.utf8') |
| from colored_formatter import ColoredFormatter | ||
|
|
||
| import locale | ||
| import codecs |
| output_charset = 'cp437' | ||
|
|
| except UnicodeDecodeError: | ||
| try: | ||
| realstdout.write(read.decode(DEFAULT_CHARSET)) | ||
| realstdout.write(read.decode('cp437', errors='replace')) | ||
| except Exception as e: |
| except Exception as e: | ||
| log.error(e) | ||
|
|
||
| log.error(e) |
|
Thanks for the contribution here, and apologies for the long silence on this one. This has been open for a couple of years now, and the plugin has moved on quite a bit in the meantime (recent Rundeck 6.0 / Python tooling updates, plus more general codepage/output-charset handling landed in #104 and #108). At this point the underlying special-character issue you were hitting should be addressable through the existing If you're still running into character-encoding issues on non-English Windows nodes, please open a new issue on rundeck/rundeck with the details and we'll take a look. Thanks again for flagging the original problem. |