I have a pretty basic golang question.
Given an arbitrary string like "echo foo"
, or "CGO_ENABLED=0 go build -o ./bin/echo -a main.go"
, what is the idiomatic way to parse/run that command using os/exec
?
The way that I got this working seems pretty hacky, and I'm looking for a more idiomatic approach.
userInput = "CGO_ENABLED=0 go build -o ./bin/echo -a main.go"
command := exec.Command("/bin/bash", "-c", userInput)
out, err := command.Output()
if err != nil {
fmt.Println(err)
}