go中如何执行docker命令

func RunCommand(cmd string) string {
   if runtime.GOOS == "windows" {
      return runInWindows(cmd)
   } else {
      return runInLinux(cmd)
   }
}

func runInLinux(cmd string) string {
   //log.Info("Running Linux cmd:", cmd)
   result, err := exec.Command("/bin/sh", "-c", cmd).Output()
   //log.Info("err", err)
   if err != nil {
      //log.Error(err.Error())
   }
   return string(result)
}

func runInWindows(cmd string) string {
   //log.Info("Running Win cmd:", cmd)
   result, err := exec.Command("cmd", "/c", cmd).Output()
   if err != nil {
      //log.Error(err.Error())
   }
   return string(result)
}

_ = RunCommand("docker exec 7a30742796ae /bin/bash -c \"mkdir fileName9\"")

你可能感兴趣的:(go,docker,java,服务器,windows)