-
Notifications
You must be signed in to change notification settings - Fork 18k
os/exec: automatic encoding conversion for stdout/stderr on Windows #69709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting this issue @lime2008. I'm moving this out of the proposal process given that you are suggesting that it can be fixed without adding new APIs. Let's treat this a bug fix rather than a proposal for now. Could you provide some more detailed steps for reproducing this issue on my PC? |
Below is a script that demonstrates the problem: package main
import (
"fmt"
"log"
"os/exec"
)
func main() {
cmdRunner := exec.Command("cmd", "/C", "echo 中文字符测试 any chinese character test")
output, err := cmdRunner.Output()
if err != nil {
log.Printf("Error executing command: %s", err)
output = []byte(fmt.Sprintf("Error: %s", err.Error()))
}
//utf8Result, err := EnsureUTF8(output)
utf8Result := output
fmt.Print(string(utf8Result))
} |
I'm concerned that os/exec currently treats output as a stream of bytes, not necessarily text that has an encoding that needs to be translated. What happens when transparent handling tries to convert binary data? |
How about add an interface to explicitly convert |
since most text encoding implementations are outside of the standard library, it seems any converter would be too. |
I apologize for the delay in replying you. |
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:
gbk
in China).os/exec
does not account for this difference while gettingstdout
, 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:os/exec
.Benefits:
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.The text was updated successfully, but these errors were encountered: