How can I launch a process that is not a file in Go (e.g. open a web page)

go

Solution

`"http://localhost:4001/"` is a URL, it can not be executed, but you can execute a web browser (e.g. `firefox`) and pass the URL as first argument.

On Windows, OS X, and Linux helper programs exist which can be used to start the default web browser. I guess there is a similar thing for FreeBSD and Android, but I am not sure about it. The following snippet should work on Windows, OS X, and most Linux distros:

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

Problem

I want to open a web browser: ``` 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) } ``` and I get the error ``` ERROR: exec: "http://localhost:4001": file does not exist ``` Edit: What I want to achieve is the same as in Windows and C# when you do: ``` Process.Start("http://localhost:4001") ``` With it a new instance of your default browser will launch showing the URL

Original source