Bruce
Bruce

Reputation: 301

golang exec.Command execute bash exit status 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.

Upvotes: 1

Views: 4819

Answers (2)

marks
marks

Reputation: 31

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 "*".

Upvotes: 0

putu
putu

Reputation: 6444

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 *"`)

Upvotes: 4

Related Questions