My understanding is you have some structure like this:
type myData struct {
// ...
Command string
// ...
}
var data = myData{
// ...
Command: "fork/exec mkdir /root/camarche"
// ...
}
And you want to run that command with exec.Command
. Is that right? If so, will any of the arguments to your commands have spaces? If not, you should be able to use string.Fields
:
fields := strings.Fields(data.Command)
cmd := exec.Command(fields[0], fields[1:]...)
If they might have spaces and will be quoted, you will need to parse the arguments. After Googling, it looks like there are packages that can do this for you such as github.com/kballard/go-shellquote which can split your single string into all of the fields.