Logo

Programming-Idioms

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

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Ruby implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
uses LclIntf;
b := OpenUrl(s);
import std.process;
browse(s);
import webbrowser
webbrowser.open(s)
import "github.com/skratchdot/open-golang/open"
b := open.Start(s) == nil
func openbrowser(url string) {
	var err error

	switch runtime.GOOS {
	case "linux":
		err = exec.Command("xdg-open", url).Start()
	case "windows":
		err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
	case "darwin":
		err = exec.Command("open", url).Start()
	default:
		err = fmt.Errorf("unsupported platform")
	}
	if err != nil {
		log.Fatal(err)
	}

}
use webbrowser;
webbrowser::open(s).expect("failed to open URL");
using System.Diagnostics;
var b = true;
try
{
    Process.Start(new ProcessStartInfo()
    {
        FileName = s,
        UseShellExecute = true,
    });
}
catch { b = false; }
use Browser::Open qw(open_browser);
my $b = open_browser $s;