1
cmd := exec.Command("bash", "-c", "rm -rf *")
cmd.Dir = "/root/media/"
err := cmd.Run()
if err != nil {
    fmt.Println(err)
    fmt.Fprintf(w, "'rm -rf *' command failed.")
}

"err": exit with status 1 I think I am not writing exec.Command correctly, but I cannot fix this.

2 Answers 2

4

The command that is going to be executed in bash should be enclosed with double quote (or single quote), e.g.

cmd := exec.Command("bash", "-c", `"rm -rf *"`)
Sign up to request clarification or add additional context in comments.

Comments

0

I met this similar error, I think you need to replace "*" to the absolute path.

Like below:

cmd := exec.Command("bash", "-c", "rm -rf <your path>")

Not use "*".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.