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)
        }   
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 layui 代码问题解决
  • ¥15 TCP传输时不同网卡传输用时差异过大
  • ¥15 请各位看看我写的属于什么算法,或者有更正确的写法?
  • ¥15 html5 qrcode 扫描器
  • ¥15 爬取网页信息并保存需要完整代码
  • ¥15 一分十不等功分器阻设计问题,请问这个56Ω怎么得到的
  • ¥15 (标签-matlab)
  • ¥100 求看看这个数学建模,有偿
  • ¥15 深度学习目标检测现在框架加注意力的创新可以投几区?
  • ¥15 PdfiumViewer pdf转图片