I've written a go function to execute commands using bash inside docker container from ubuntu 20.04.
func commandExecution(command string) (error, string, string) {
var output bytes.Buffer
var error bytes.Buffer
cmd := exec.Command("bash", "-c", command)
cmd.Stdout = &output
cmd.Stderr = &error
err := cmd.Run()
return err, output.String(), error.String()
}
when I try to execute some commands like below
err, _, _ := commandExecution("sudo mkdir -p " + directory)
or
err, _, _ := commandExecution("sudo cp " + source + " " + destination)
I'm just getting the
error exit status 127
I tried executing again directly
docker exec container bash -c mv --help
mv: missing file operand
Help me out!
sudo, not the actual code. Try running something that does not require root priveleges. Also this might be relevant stackoverflow.com/questions/25845538/…directorycontains punctuation, likedirectory := "foo; sudo rm -rf /"? Can you use an array of single-word arguments and avoid thebash -cwrapper?