dpno17028 2017-10-21 02:46
浏览 968
已采纳

golang exec.Command执行bash退出状态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.

  • 写回答

1条回答 默认 最新

  • douqian5920 2017-10-21 04:21
    关注

    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 *"`)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?