Logo

Programming-Idioms

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

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.

cmd = case  RbConfig::CONFIG['host_os']
  when  /mswin|mingw|cygwin/ then "start "
  when  /darwin/ then "open "
  when  /linux|bsd/ then "xdg-open "
  else raise "No OS detected"
end
    
b = system cmd + s

b contains the info which is returned by the OS
using System.Diagnostics;
var b = true;
try
{
    Process.Start(new ProcessStartInfo()
    {
        FileName = s,
        UseShellExecute = true,
    });
}
catch { b = false; }

New implementation...
< >
Bart