I tried running this source code to get the output of 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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.