I\'m looking to execute a shell command in Go and get the resulting output as a string in my program. I saw the Rosetta Code version:
package main
import \"f
// 封装exec ,有shell= true 这样的选项
func Cmd(cmd string, shell bool) []byte {
if shell {
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
panic("some error found")
}
return out
} else {
out, err := exec.Command(cmd).Output()
if err != nil {
panic("some error found")
}
return out
}
}
you may try this .