Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #164 Open URL in the default browser

Open the URL s in the default browser.
Set the boolean b to indicate whether the operation was successful.

var err error
switch runtime.GOOS {
case "linux":
	err = exec.Command("xdg-open", s).Start()
case "windows":
	err = exec.Command("rundll32", "url.dll,FileProtocolHandler", s).Start()
case "darwin":
	err = exec.Command("open", s).Start()
default:
	err = fmt.Errorf("unsupported platform")
}
b := err == nil
import "github.com/skratchdot/open-golang/open"
b := open.Start(s) == nil
using System.Diagnostics;
var b = true;
try
{
    Process.Start(new ProcessStartInfo()
    {
        FileName = s,
        UseShellExecute = true,
    });
}
catch { b = false; }

New implementation...
< >
Bart