tags:

views:

1299

answers:

6

In Python, you can do this:

import webbrowser
webbrowser.open_new("http://example.com/")

It will open the passed in url in the default browser

Is there a ruby equivalent?

+1  A: 

Windows Only Solution:

require 'win32ole'
shell = WIN32OLE.new('Shell.Application')
shell.ShellExecute(...)

Shell Execute on MSDN

Ken
A: 

If it's windows and it's IE, try this: http://rubyonwindows.blogspot.com/search/label/watir also check out Selenium ruby: http://selenium.rubyforge.org/getting-started.html

HTH

Zsolt Botykai
The point was that you don't have to guess what the default browser is. If it was IE, there'd be no question of what to do.
Adriano Varoli Piazza
+1  A: 

Mac-only solution:

system("open", "http://stackoverflow.com/")

or

`open http://stackoverflow.com/`
Ryan McGeary
+15  A: 

Cross-platform solution

First, install the Launchy gem:

$ [sudo] gem install launchy

Then, you can run this:

require 'rubygems'
require 'launchy'

Launchy.open("http://stackoverflow.com")
Ryan McGeary
+1  A: 

This also works:

system("start #{link}")
palmsey
Note, this is Windows-only solution.
Ryan McGeary
+3  A: 

Simplest Win solution:

`start http://www.example.com`
James Baker