这是我尝试过的:package mainimport ( "fmt" "os/exec")func main() { fmt.Println("Removing build directory") if err := exec.Command("cmd", "/S /Q", "RD", "c:\\build").Run(); err != nil { fmt.Printf("Error removing build directory: %s\n", err) } if err := exec.Command("cmd", "/C", "mkdir", "c:\\build").Run(); err != nil { fmt.Printf("Error making new build directory: %s\n", err) }}我的输出是:Removing build directoryError making new build directory: exit status 1所以删除时我没有收到任何错误,但它不会删除任何内容。这是为什么 ?
1 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
试试这个..
func main() {
fmt.Println("Removing build directory")
c := exec.Command("cmd", "/C", "rd /S /Q", "C:\\build")
if err := c.Run(); err != nil {
fmt.Println("Error: ", err)
}
if err := exec.Command("cmd", "/C", "mkdir", "c:\\build").Run(); err != nil {
fmt.Printf("Error making new build directory: %s\n", err)
}
}
- 1 回答
- 0 关注
- 196 浏览
添加回答
举报
0/150
提交
取消