第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何啟動Go中非文件的進(jìn)程(例如,打開網(wǎng)頁)

如何啟動Go中非文件的進(jìn)程(例如,打開網(wǎng)頁)

Go
慕運(yùn)維8079593 2021-04-27 13:14:09
我想打開一個網(wǎng)絡(luò)瀏覽器:c, err := exec.Command("http://localhost:4001").Output()if err != nil {    fmt.Printf("ERROR: %v, %v\n",err,c)} else {    fmt.Printf("OK:%v\n",c)}我得到了錯誤ERROR: exec: "http://localhost:4001": file does not exist編輯:當(dāng)您執(zhí)行以下操作時,我要實(shí)現(xiàn)的功能與Windows和C#中的功能相同:Process.Start("http://localhost:4001")有了它,您的默認(rèn)瀏覽器的新實(shí)例將啟動,顯示URL
查看完整描述

3 回答

?
慕勒3428872

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")

}


查看完整回答
反對 回復(fù) 2021-05-10
?
回首憶惘然

TA貢獻(xiàn)1847條經(jīng)驗 獲得超11個贊

在Windows下使用:

exec.Command("cmd", "/c", "start", "http://localhost:4001/").Start()


查看完整回答
反對 回復(fù) 2021-05-10
?
慕姐8265434

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()



查看完整回答
反對 回復(fù) 2021-05-10
  • 3 回答
  • 0 關(guān)注
  • 254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號