简体   繁体   English

如何输出`exec.Command`的输出数据而没有断字符

[英]How to output the output data of `exec.Command` without broken characters

I tried running this source code to get the output of cmd.我尝试运行此源代码以获取 cmd 的输出。

cmd, err := exec.Command("systeminfo").Output()
if err != nil {
    return nil, err
}
fmt.Println(string(cmd))
return cmd, nil

But the result is like this picture.但结果就像这张图。

在此处输入图片说明

The output includes Korean, and only English and numbers are displayed, all other characters are broken.输出包括韩文,只显示英文和数字,其他字符全断。

I'm not sure how to solve these encoding problems.我不确定如何解决这些编码问题。

I solved the problem with this code我用这段代码解决了这个问题

//import
//"golang.org/x/text/encoding/korean"
//"golang.org/x/text/transform"
cmd, err := exec.Command("systeminfo").Output()
if err != nil {
    return nil, err
}

bufs := new(bytes.Buffer) 
wr := transform.NewWriter(bufs, korean.EUCKR.NewDecoder())
wr.Write(cmd)
wr.Close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM