3 回答

TA貢獻(xiàn)1848條經(jīng)驗 獲得超6個贊
"http://localhost:4001/"是URL,無法執(zhí)行,但您可以執(zhí)行網(wǎng)絡(luò)瀏覽器(例如firefox)并將URL作為第一個參數(shù)傳遞。
在Windows上,存在OS X和Linux幫助程序,這些程序可用于啟動默認(rèn)的Web瀏覽器。我想FreeBSD和Android也有類似的事情,但是我不確定。以下代碼段應(yīng)在Windows,OS X和大多數(shù)Linux發(fā)行版上運(yùn)行:
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", "http://localhost:4001/").Start()
case "windows", "darwin":
err = exec.Command("open", "http://localhost:4001/").Start()
default:
err = fmt.Errorf("unsupported platform")
}

TA貢獻(xiàn)1847條經(jīng)驗 獲得超11個贊
在Windows下使用:
exec.Command("cmd", "/c", "start", "http://localhost:4001/").Start()

TA貢獻(xiàn)1813條經(jīng)驗 獲得超2個贊
使用
exec.Command("open", "http://localhost:4001/").Start()
在以上tux21b的答案中,Windows上對我不起作用。但是這樣做:
exec.Command(`C:\Windows\System32\rundll32.exe`, "url.dll,FileProtocolHandler", "http://localhost:4001/").Start()
- 3 回答
- 0 關(guān)注
- 254 瀏覽
添加回答
舉報