golang: run default application for a pdf file on windows

前端 未结 2 1490
挽巷
挽巷 2021-02-15 23:22

I\'d like to open a PDF file in the filesystem from go with the default application. How can I do that? From the command line I just write the filename of the pdf file and the a

相关标签:
2条回答
  • 2021-02-16 00:05
    exec.Command("rundll32.exe", "url.dll,FileProtocolHandler", "path_to_foo.pdf")
    

    should also handle it.

    Note that still the right way to do it is to use a C wrapper around the ShellExecute() API function exported by shell32.dll, and the "w32" library seems to provide this wrapper right away.

    0 讨论(0)
  • 2021-02-16 00:20

    You must launch cmd /C start foo.pdf. This will let the start command find the correct executable for you.

    cmd := exec.Command("cmd", "/C start path_to_foo.pdf")
    
    0 讨论(0)
提交回复
热议问题