Using ruby 1.9.2 I am writing a windows script that intends to launch a browser on a URL that contains a number of parameters. I have tried the various ways of launching a browser process: 'start #{url}` system( "start #{url}" ) ...
My URL contains a number of parameters and the开发者_开发知识库refore contains &'s. The problem is that the &'s seem to be interpreted by the shell and I have not figured out how to escape them such that they are correctly passed to the browser.
Any ideas? Thanks!
You can use system
with several arguments:
Executes command in a subshell. command is one of following forms.
[...]
cmdname, arg1, ...
: command name and one or more arguments (no shell)
That would skip the shell completely and bypass the whole escaping issue. Try this:
system('start', url)
I'm not sure how start
works with Windows but that should work if it is a separate executable.
Launchy is also a fantastic gem that allows you to do this in a cross-platform way (in case you want to go beyond Windows).
Example:
require 'rubygems'
require 'launchy'
Launchy.open('http://www.google.com/search?&q=ruby')
精彩评论