使用exec包command命令,命令之间空格就是多个参数拼接。
代码语言:javascript复制package main
import (
"fmt"
"os/exec"
)
func main() {
filename := "./const.go"
cmd := exec.Command("go", "fmt", filename)
fmt.Println(cmd)
if out, err := cmd.CombinedOutput(); err != nil {
fmt.Println(string(out), err)
return
}
fmt.Println("End")
cmd = exec.Command("docker", "build", "-t", filename)
fmt.Println(cmd)
}