Can you run a command line script with arguments, without typing'ruby' first?

J

James Britt

Kyle said:
Jayson, if your not on a real OS, you need to associate the extension
.rb with the interpreter. It's been a little while since I've done
this in windows, but it's actually pretty straightforward. You may
have to google for how to associate the script with the interpreter
though, as I don't recall the _exact_ steps.


That *used* to happen when installing the 1-click[sic] version.

(It's in the PATHEXT system environment variable. I think there has to
be something n the registry as well, but you could get that by
right-clicking a .rb file and selecting the app to always open files of
that type.)


Anyways, on my Vista box, it all works fine. I type the name of a
script, no file extension, passing args, and all is super cool awesome.

I've never had to explicitly invoke ruby, even on XP. It's one case
where Windows did the right thing reliably. :)





--
James Britt

www.happycamperstudios.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
 
M

Mohit Sindhwani

Daniel said:
Are command-line arguments included in the file association?
There should be something like "...\ruby.exe" "$*" or
"...\ruby.exe" "%1" "%2" "%3" "%4" "%5" (up to %9, this form is
restricted to 9 arguments).

Daniel

OK! I have it here... I just checked through the Windows XP stuff on my
PC...
I think this is what you need to do.

1. Open a folder.
2. Select Tools > Folder Options
3. Tab: File Types
4. Scroll down till you find RB in the list
5. In the box that says 'Details for ...' click on [Advanced]
6. There is a box called 'Actions'
7. Select the open action - create a new one called open if it isn't there
8. In the pop-up window, these are my settings:
Action: open
Application used to perform this action: "c:\ruby\bin\ruby.exe" "%1" %*
[x] use DDE
Application: ruby
Topic: System
(other fields blank)
[OK]

Try?

Cheers,
Mohit.
11/26/2008 | 1:50 AM.
 
J

Jayson Williams

WoooHooooo!!! That did it. The arguments were there except the last
%* was in quotes. Took the quotes off and presto. I can now do
my_script args

and get the correct output.

Thanks everyone!

Jayson

Daniel said:
Are command-line arguments included in the file association?
There should be something like "...\ruby.exe" "$*" or
"...\ruby.exe" "%1" "%2" "%3" "%4" "%5" (up to %9, this form is
restricted to 9 arguments).

Daniel

OK! I have it here... I just checked through the Windows XP stuff on my
PC...
I think this is what you need to do.

1. Open a folder.
2. Select Tools > Folder Options
3. Tab: File Types
4. Scroll down till you find RB in the list
5. In the box that says 'Details for ...' click on [Advanced]
6. There is a box called 'Actions'
7. Select the open action - create a new one called open if it isn't ther= e
8. In the pop-up window, these are my settings:
Action: open
Application used to perform this action: "c:\ruby\bin\ruby.exe" "%1" %*
[x] use DDE
Application: ruby
Topic: System
(other fields blank)
[OK]

Try?

Cheers,
Mohit.
11/26/2008 | 1:50 AM.
 
M

Mohit Sindhwani

Jayson said:
WoooHooooo!!! That did it. The arguments were there except the last
%* was in quotes. Took the quotes off and presto. I can now do
You're most welcome :)
 
D

Daniel Schömer

Jayson said:
I don't believe these arguments are included in the association. I am
not sure how to add them.

I don't remember the exact menu/option names, but this should be
the way to check:

- Windows Explorer, Menu 'Extras', 'Folder Options'. Or Control
Panel, 'Folder Options'
- Tab 'Filetypes'
- Scroll to '.rb' and select
- Button 'Advanced' or 'Extended' on the bottom right
- Now there should be a textfield containing '...\ruby.exe'. Try
to add "%*" or "%1" "%2" ... (try with and without quotes)
after ruby.exe

(%1 gets replaced by the first argument, %2 by the second,
limited to 9 arguments. %* should be replaced by all arguments)

Daniel
 
J

Jayson Williams

Frustratingly, I got this working fine at work. I can type
my_script args
and I get the proper results. Now my propblem is my home pc. I have
tried all the fixes above, but I still have to type

my_script.rb args
unless I inclued the .rb extension, the script will not run.

 
M

Mohit Sindhwani

Jayson said:
Frustratingly, I got this working fine at work. I can type
my_script args
and I get the proper results. Now my propblem is my home pc. I have
tried all the fixes above, but I still have to type

my_script.rb args
unless I inclued the .rb extension, the script will not run.
In general, you should need to type in the extension as part of the
program name cos the extension is what tells Windows what to do with
it. The exception is a list of extensions that Windows treats as
executables. These are usually .exe, .com, . bat, .cmd etc - in these
cases, typing the extension is optional.

This is controlled in a variable called PATHEXT in the environment. In
a command window, I did:
command>set

This gives me a list of extensions that are already there:
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW

(note .rb and .rbw at the end)

Add that to your PATHEXT and try?

Cheers,
Mohit.
11/29/2008 | 4:13 PM.
 
J

Jayson Williams

Mohit,

YOU ROCK !
I am embarrassed to have been goofing with computers for so many years
without knowing these basics. Anyway everything is working the way I
want, and I have learned some very useful basics.
Thanks!

Jayson
 
M

Mohit Sindhwani

Jayson said:
Mohit,

YOU ROCK !
I am embarrassed to have been goofing with computers for so many years
without knowing these basics. Anyway everything is working the way I
want, and I have learned some very useful basics.
Thanks!
me too :)
I had these items in peripheral vision, but your queries made me chase
them down :p

Cheers,
Mohit.
11/30/2008 | 1:42 PM.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top