I want my method to receive a command to exec as a string. If the input string has spaces, how do I split it into cmd, args for os.exec?
The documentation says to create my Exec.Cmd struct like
cmd := exec.Command("tr", "a-z", "A-Z")
This works fine:
a := string("ifconfig")
cmd := exec.Command(a)
output, err := cmd.CombinedOutput()
fmt.Println(output) // prints ifconfig output
This fails:
a := string("ifconfig -a")
cmd := exec.Command(a)
output, err := cmd.CombinedOutput()
fmt.Println(output) // 'ifconfig -a' not found
I tried strings.Split(a), but receive an error message: cannot use (type []string) as type string in argument to exec.Command