I'm trying to execute a command using go.
executableCommand := strings.Split("git commit -m 'hello world'", " ")
executeCommand(executableCommand[0], executableCommand[1:]...)
cmd := exec.Command(command, args...)
But here is what I get
error: pathspec 'world"' did not match any file(s) known to git.
exit status 1
This is because -m
gets 'hello
only and not 'hello world'
since the command line is split using " "
.
Any idea to make it work?
What you want is actually hard to achieve without help of shell that interprets quotes etc. So you may use shell to run your command.
exec.Command("sh", "-c", "echo '1 2 3'")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With