Invoking browser from Ruby script with URL argument: How?

Hi,

I've got the folowing script:
require "fileutils"

path = "K:/_Utilities/Apache/xampp/"
FileUtils::cd path
names = Dir.glob("**/index.html")
(0..4).each { |i|
      name = names[i]
      address = "file://" + path + name
      puts address
      exec address
}

It runs fine without line 10, "exec address", and produces:
file://K:/_Utilities/Apache/xampp/apache/htdocs/index.html
file://K:/_Utilities/Apache/xampp/htdocs/index.html
file://K:/_Utilities/Apache/xampp/htdocs/restricted/index.html
file://K:/_Utilities/Apache/xampp/licenses/gd/index.html
file://K:/_Utilities/Apache/xampp/php/docs/Structures_Graph/docs/html/index.html

But with line 10 active, I hang with:
K:\>ruby K:\_Projects\Ruby\_Ruby_Tests\TestDirTraversal
\TestDirTraversal.rb
file://K:/_Utilities/Apache/xampp/apache/htdocs/index.html
K:/_Projects/Ruby/_Ruby_Tests/TestDirTraversal/TestDirTraversal.rb:
10:in `exec': Invalid argument - file://K:/_Utilities/Apache/xampp/apache/htdocs/in
dex.html (Errno::EINVAL)
        from K:/_Projects/Ruby/_Ruby_Tests/TestDirTraversal/
TestDirTraversal.rb:10:in `block in <main>'
[snip]

Of course, if I pasted these addresses on successive lines of Word
(with space characters appended to each), I'd have a series of
hyperlinks that could control-click to invoke the respective URLs in
Firefox.

Is there a way I can repair the code here to achieve the equivalent
effect with Ruby?

Thanks in advance for any education you may offer,
Richard

exec([env,] command... [,options])
Replaces the current process by running the given external command

but

file://K:/_Utilities/Apache/xampp/apache/htdocs/index.html

isn't a command.

http://stackoverflow.com/questions/2159735/how-to-let-ruby-call-default-browser-to-open-localfile

Possibly
exec "firefox #{address}"

Colin

Hi 7-stud,

Long time no "see". Thanks for looking into my question.

file://K:/_Utilities/Apache/xampp/apache/htdocs/index.html

isn't a command.

Yeah, I know, but my question is how to repair my code so that it
works. Or more specifically, what command can I take which accepts
the text of a URL as an argument and invokes my browser with that
command as an argument?

Do you have a further idea? I greatly appreciate learning any other
idea you might have on the question.

Best wishes,
Richard

Colin,

exec "firefox #{address}"

You're my hero!! I couldn't think of what command I could use to
invoke the browser on my machine. I wish I had possessed enough
imagination to at least try that idea before posting my question. I
did harbor the fancy of poking through Rails source code, thinking I
might find a clue there. But that seemed daunting to me.

Best wishes,
Richard

Colin,

> exec "firefox #{address}"

I don't think this would work on a max, since GUI apps aren't normally
in $PATH. You might be interested in the launchy gem.

Fred

Hi Fred,

I'm happy our paths crossed again.

The launchy gem looks cool. The page I found it on also advertised
Process Explorer from SysInternals that replaces Window's
StartMenu ... something I've wanted for a long time. So, it's a
double-hitter.

Thanks and best wishes,
Richard

RichardOnRails wrote in post #1015562:

Hi 7-stud,

Long time no "see". Thanks for looking into my question.

file://K:/_Utilities/Apache/xampp/apache/htdocs/index.html

isn't a command.

Yeah, I know, but my question is how to repair my code so that it
works. Or more specifically, what command can I take which accepts
the text of a URL as an argument and invokes my browser with that
command as an argument?

Do you have a further idea?

Well, I provided a link.

On a Mac, you don't need launchy, just do:

open http://example.com/whatever

You don't need launchy on any platform but it takes away from you the
hassle of deciding which strategy to use for a given environment.

Fred

Hi again,

Do you have a further idea?

Well, I provided a link.

Thanks for that link in your second post. I only received it about an
hour after your original response, which only pointed out that I
lacked a function reference. Hence my request for further idea(s).

Now I have a wealth of good solutions: Yours, Colin's and Fred's

Thanks to you and them,
Richard