Skip to content

os/exec: automatic encoding conversion for stdout/stderr on Windows #69709

@lime2008

Description

@lime2008

Proposal: os/exec: Handle Windows Standard Streams Encoding

Currently, the os/exec package does not differentiate between the default behavior of different Windows versions regarding standard output and error encoding. This can lead to encoding issues when running commands that output non-UTF-8 characters in Windows with the "Use Unicode UTF-8 for worldwide language support" beta feature enabled.

Problem:

  • Windows traditionally uses locale-specific encodings for console output (e.g., gbk in China).
  • Windows introduced a beta feature to enforce UTF-8 encoding for all console applications.
  • os/exec does not account for this difference while getting stdout, potentially leading to garbled output when this beta feature is not enabled.

Proposed Solution:

Introduce a mechanism in os/exec to handle Windows console encoding variations, specifically:

  1. Detection: Automatically detect if the Windows UTF-8 beta feature is active.
  2. Transparent Handling: Based on the chosen configuration, seamlessly handle encoding and decoding of output streams within os/exec.

Benefits:

  • Code can be more consistent by removing the need for platform-specific encoding workarounds.
  • Improved compatibility with applications relying on UTF-8 output.
  • Enhanced user experience by avoiding garbled characters in console output.

This feature request aims to improve the reliability and user-friendliness of os/exec when interacting with console applications in diverse Windows environments. Thank you to everyone who reviews this request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions