在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
package main // 打开系统默认浏览器 import ( "fmt" "os/exec" "runtime" "time" ) // 不同平台启动指令不同 var commands = map[string]string{ "windows": "explorer", "darwin": "open", "linux": "xdg-open", } func Open(uri string) error { // runtime.GOOS获取当前平台 run, ok := commands[runtime.GOOS] if !ok { return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS) } cmd := exec.Command(run, uri) return cmd.Run() } func main() { fmt.Println(exec.Command("start","http://127.0.0.1").Output()) time.Sleep(time.Minute) }
|
请发表评论