这就是我的尝试:
package main
import (
"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 directory
Error making new build directory: exit status 1
所以我在删除时没有收到任何错误,但它不会删除任何内容。
为什么?
答案 0 :(得分:0)
试试这个..
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)
}
}