Pass ruby-generated URL into a browser for execution: How?

R

RichardOnRails

I've got the Ruby script:

require "fileutils"

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

With the final statement (exec address) commented out, I get:
K:\>ruby K:\_Projects\Ruby\_Ruby_Tests\TestDirTraversal
\TestDirTraversal.rb
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

With the final statement active, I get the crash:
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>'
from K:/_Projects/Ruby/_Ruby_Tests/TestDirTraversal/
TestDirTraversal.rb:6:in `each'
from K:/_Projects/Ruby/_Ruby_Tests/TestDirTraversal/
TestDirTraversal.rb:6:in `<main>'

I'm running WinXP-Pro/SP3, Ruby 1.9.2 and Firefox 5.0.

If I copy/paste these addresses into Firefox address bar, the work as
expected. If I paste them into a Word document with RETURN after each
one, I have a set of links I could click or double-click to start
them up in Firefox. Is there a way to do this in pure Ruby?

Is this the right newsgroup for this kind of question?

Thanks in advance,
Richard
 
R

Robert Klemme

I've got the Ruby script:

require "fileutils"

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

With the final statement (exec address) commented out, I get:
K:\>ruby K:\_Projects\Ruby\_Ruby_Tests\TestDirTraversal
\TestDirTraversal.rb
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

With the final statement active, I get the crash:
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>'
from K:/_Projects/Ruby/_Ruby_Tests/TestDirTraversal/
TestDirTraversal.rb:6:in `each'
from K:/_Projects/Ruby/_Ruby_Tests/TestDirTraversal/
TestDirTraversal.rb:6:in `<main>'

I'm running WinXP-Pro/SP3, Ruby 1.9.2 and Firefox 5.0.

If I copy/paste these addresses into Firefox address bar, the work as
expected. If I paste them into a Word document with RETURN after each
one, I have a set of links I could click or double-click to start
them up in Firefox. Is there a way to do this in pure Ruby?


You cannot execute a URL directly via exec or system. You either need
to pass the path to firefox binary as first argument or use cmd's built
in command "start" to start a URL.
Is this the right newsgroup for this kind of question?

Think so, yes.

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top