running a file

J

John Pasqa

ok, i'm writing a ruby program that interprets some text and does stuff
with it, but thats not what i'm here to ask about.
What I want to know is how would I make it so the user can right-click
and open a file with my program. Just like how if you right click a .rb
file you can run it with the ruby MRI. All I need is to get the text in
the file into a variable in the program when the user opens it. Any
suggestions?

Thanks
John
 
J

John Pasqa

no, i just want to be able to right click and run a file and run it with
my program.
 
E

Eric Christopherson

ok, i'm writing a ruby program that interprets some text and does stuff
with it, but thats not what i'm here to ask about.
What I want to know is how would I make it so the user can right-click
and open a file with my program. Just like how if you right click a .rb
file you can run it with the ruby MRI. All I need is to get the text in
the file into a variable in the program when the user opens it. Any
suggestions?

Assuming you're using Windows, you will most likely have to edit the
registry entry for the file type you want to open with your script.
 
J

John Pasqa

i am using windows, but opening a file with my program doesn't do
anything. I need to know what code will allow the program to read the
file when the file is opened with my program.
 
S

Siep Korteling

Eric said:
Assuming you're using Windows, you will most likely have to edit the
registry entry for the file type you want to open with your script.

Open explorer, menu Extra --> Folder options --> tab File types, select
the file type, for instance .txt --> advanced --> new

Under "action" type a name
The other textfield should propably something like
path\to\ruby.exe path\to\your_progam.rb %1

hth,

Siep
 
E

Eric Christopherson

Open explorer, menu Extra --> Folder options --> tab File types, select
the file type, for instance .txt --> =A0advanced --> new

Under "action" type a name
The other textfield should propably something like
path\to\ruby.exe path\to\your_progam.rb %1

Siep, I was about to suggest the same thing, except when I tried it,
it said it couldn't find the Ruby executable. It turned out that I
needed to put quotes around the Ruby pathname (since it has spaces on
my machine).
 
J

John Pasqa

yes thats what im trying to do, but i want to do it by having the user
right-click> open with> my program that would hopefully give my program
the directory of the file, which i could then use. as opposed to the way
i have it now where they need to type in the filename. i read through
the file section on ruby-doc, no help there.
 
J

John Pasqa

Chad said:
How do you have the program written to take the path/filename now? Have
you tried feeding it a filename as a command argument? I'm wildly
guessing here, because I've never done what you're trying to do, but it
seems (intuitively, to me at least) like that should work.

For example, if you write your program such that this works:


. . . then it seems like double-clicking the file, when the filename
extension in question is associated with your program via MS Windows'
file type association mechanism, should automatically feed it to the
program just as it would be fed to the program as a command argument.
I'd think it would be worth a try.

If I was using an MS Windows system right this instant, I'd give it a
try
just to make sure before offering the suggestion, but I figure it's
worth
telling you my idea in case you get a chance to test it before I find
myself sitting in front of my XP test system.

thats not how I have it now, but I think it would work beautifully. What
I need is the code that would let my program take a command argument,
any clues as to where i could find that?
 
J

John Pasqa

thanks so much, thats exactly what I was looking for, thanks again for
everyones time.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top