doumicheng6732 2019-06-26 14:33
浏览 211
已采纳

如何使用golang运行.msi文件?

I'm writing a function that will run an msi file by taking in the applications path as a parameter. Right now the function is returning an error code stating that the application's path is not a valid Win32 application. This function works for .exe files, but not .msi files. How can I refactor it to work for .msi files?

func Run(application string) {
    cmd := exec.Command(application)
    err := cmd.Run()
    if err != nil {
        log.Fatalf("cmd.Run() failed with %s
", err)
    }
}
  • 写回答

1条回答 默认 最新

  • doumu6997 2019-06-26 14:38
    关注

    you can simply run it through windows's command line

       func main(){    
        c := exec.Command("cmd", "/C", "msiexec /a \"pathtotheMSIfile\"")
        if err := c.Run(); err != nil { 
            fmt.Println("Error: ", err)
        }   
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?