Skip to content

Update winrm-exec.py - #97

Closed
GrymnDolen wants to merge 1 commit into
rundeck-plugins:mainfrom
GrymnDolen:patch-1
Closed

Update winrm-exec.py#97
GrymnDolen wants to merge 1 commit into
rundeck-plugins:mainfrom
GrymnDolen:patch-1

Conversation

@GrymnDolen

Copy link
Copy Markdown
  1. Set the encoding configuration for sys.stdout to UTF-8 for handling special characters correctly.
    
  2. Configured the locale to 'fr_FR.utf8' for special character support like "é" and "ê."
    
  3. Renamed variables to adhere to Python naming conventions.
    
  4. Modified the output encoding to 'cp437' for compatibility with the Windows CMD console.
    
  5. Adjusted the decoding of command output in the while loop to use 'cp437' encoding.
    

@fdevans
fdevans requested a review from Copilot March 18, 2026 21:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cp437 decoding 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.

Comment thread contents/winrm-exec.py
Comment on lines +19 to +20
sys.stdout.reconfigure(encoding='utf-8')
locale.setlocale(locale.LC_ALL, 'fr_FR.utf8')
Comment thread contents/winrm-exec.py
import codecs

sys.stdout.reconfigure(encoding='utf-8')
locale.setlocale(locale.LC_ALL, 'fr_FR.utf8')
Comment thread contents/winrm-exec.py
from colored_formatter import ColoredFormatter

import locale
import codecs
Comment thread contents/winrm-exec.py
Comment on lines +307 to +308
output_charset = 'cp437'

Comment thread contents/winrm-exec.py
Comment on lines 323 to 326
except UnicodeDecodeError:
try:
realstdout.write(read.decode(DEFAULT_CHARSET))
realstdout.write(read.decode('cp437', errors='replace'))
except Exception as e:
Comment thread contents/winrm-exec.py
except Exception as e:
log.error(e)

log.error(e)
@fdevans

fdevans commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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 RD_NODE_OUTPUT_CHARSET / RD_NODE_CODEPAGE environment variables rather than a locale/codepage override baked into the script, so I'm going to close this rather than try to carry it forward.

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.

@fdevans fdevans closed this Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants