Michael Venable
Michael Venable

Reputation: 5041

How do I launch a website (with GET parameters) in the default browser in Ruby?

How can I open a website in the user's default web browser (preferably platform-independent, but not required) using Ruby?

I've found several references to the Launchy gem, however Launchy doesn't seem to handle ampersands correctly. For example, the command

Launchy.open("http://mysite.com?param1=a&param2=b")

causes the error "'param2' is not recognized as an internal or external command. I'm using Windows and the Windows shell interprets an ampersand as a command separator, so I suspect that is causing the problem. The Launchy documentation is very sparse: http://copiousfreetime.rubyforge.org/launchy/.

Others have suggested using the Windows start command, but that has the same problem.

Upvotes: 0

Views: 280

Answers (2)

Pedro Rolo
Pedro Rolo

Reputation: 29990

How about Launchy::Browser.run("http://mysite.com?param1=a&param2=b") ?

Upvotes: 0

Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24637

Yep, it's pretty old Launchy's bug. It can be fixed adding ^ in the url before & char (as the guy who opened an issue suggests). I'll make a patch ASAP. So, right now you can use just plain system method for this job:

system("start http://google.com?a=1^&b2=2")

Upvotes: 2

Related Questions