Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Can you run a command line script with arguments, without typing'ruby' first?

Reply
Thread Tools

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

 
 
Jayson Williams
Guest
Posts: n/a
 
      11-24-2008
Hi All,

I would like to do this -> my_script arg1, arg2
This doesn't seem to work when the script has arguments.

But if I type -> ruby my_script arg1,arg2
It works fine.

Is there a way I can run the my_script without typing ruby each time?
Thanks

 
Reply With Quote
 
 
 
 
Diogo Lisboa
Guest
Posts: n/a
 
      11-24-2008
chmod a+x my_script (restrict permissions if you want)
/my_script args

or put my_script in your PATH, and just type `my_script args'

On Mon, Nov 24, 2008 at 4:47 PM, Jayson Williams
<> wrote:
> Hi All,
>
> I would like to do this -> my_script arg1, arg2
> This doesn't seem to work when the script has arguments.
>
> But if I type -> ruby my_script arg1,arg2
> It works fine.
>
> Is there a way I can run the my_script without typing ruby each time?
> Thanks
>
>




--
Diogo

 
Reply With Quote
 
 
 
 
Tim Pease
Guest
Posts: n/a
 
      11-24-2008
On Nov 24, 2008, at 11:47 AM, Jayson Williams wrote:

> Hi All,
>
> I would like to do this -> my_script arg1, arg2
> This doesn't seem to work when the script has arguments.
>
> But if I type -> ruby my_script arg1,arg2
> It works fine.
>
> Is there a way I can run the my_script without typing ruby each time?


on any *nix platform, make the script executable and put a hash-bang
line at the top

chmod 755 my_script
vim my_script
i#!/usr/bin/env ruby<Return><Esc>:wq
my_script arg1 arg2


Blessings,
TwP

 
Reply With Quote
 
Diogo Lisboa
Guest
Posts: n/a
 
      11-24-2008
> #!/usr/bin/env ruby

Yes, I forgot the shebang.

Diogo

 
Reply With Quote
 
Jayson Williams
Guest
Posts: n/a
 
      11-24-2008
I am using win os, so the shabang thing isn't an option for me. I put
the script in my ruby bin path, and I can access the script from
anywhere now, but I still have the same problem with the script not
running properly unless i type ruby first. It is as if ruby does not
attempt to read in arguments unless you explicitly pass the script
through ruby. If I call the script with the arguments without putting
'ruby' first, the args don't seem to get read.


On Mon, Nov 24, 2008 at 2:05 PM, Diogo Lisboa <> wrote:
> chmod a+x my_script (restrict permissions if you want)
> ./my_script args
>
> or put my_script in your PATH, and just type `my_script args'
>
> On Mon, Nov 24, 2008 at 4:47 PM, Jayson Williams
> <> wrote:
>> Hi All,
>>
>> I would like to do this -> my_script arg1, arg2
>> This doesn't seem to work when the script has arguments.
>>
>> But if I type -> ruby my_script arg1,arg2
>> It works fine.
>>
>> Is there a way I can run the my_script without typing ruby each time?
>> Thanks
>>
>>

>
>
>
> --
> Diogo
>
>


 
Reply With Quote
 
Glen Holcomb
Guest
Posts: n/a
 
      11-24-2008
[Note: parts of this message were removed to make it a legal post.]

On Mon, Nov 24, 2008 at 2:12 PM, Jayson Williams
<>wrote:

> I am using win os, so the shabang thing isn't an option for me. I put
> the script in my ruby bin path, and I can access the script from
> anywhere now, but I still have the same problem with the script not
> running properly unless i type ruby first. It is as if ruby does not
> attempt to read in arguments unless you explicitly pass the script
> through ruby. If I call the script with the arguments without putting
> 'ruby' first, the args don't seem to get read.
>
>
> On Mon, Nov 24, 2008 at 2:05 PM, Diogo Lisboa <>
> wrote:
> > chmod a+x my_script (restrict permissions if you want)
> > ./my_script args
> >
> > or put my_script in your PATH, and just type `my_script args'
> >
> > On Mon, Nov 24, 2008 at 4:47 PM, Jayson Williams
> > <> wrote:
> >> Hi All,
> >>
> >> I would like to do this -> my_script arg1, arg2
> >> This doesn't seem to work when the script has arguments.
> >>
> >> But if I type -> ruby my_script arg1,arg2
> >> It works fine.
> >>
> >> Is there a way I can run the my_script without typing ruby each time?
> >> Thanks
> >>
> >>

> >
> >
> >
> > --
> > Diogo
> >
> >

>
>

Yep, in Windows you have to invoke ruby first on the command line. The
shebang in the Unix world is kind of a short hand for doing this.

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

 
Reply With Quote
 
Glen Holcomb
Guest
Posts: n/a
 
      11-24-2008
[Note: parts of this message were removed to make it a legal post.]

On Mon, Nov 24, 2008 at 2:21 PM, Glen Holcomb <> wrote:

>
>
> On Mon, Nov 24, 2008 at 2:12 PM, Jayson Williams <
> > wrote:
>
>> I am using win os, so the shabang thing isn't an option for me. I put
>> the script in my ruby bin path, and I can access the script from
>> anywhere now, but I still have the same problem with the script not
>> running properly unless i type ruby first. It is as if ruby does not
>> attempt to read in arguments unless you explicitly pass the script
>> through ruby. If I call the script with the arguments without putting
>> 'ruby' first, the args don't seem to get read.
>>
>>
>> On Mon, Nov 24, 2008 at 2:05 PM, Diogo Lisboa <>
>> wrote:
>> > chmod a+x my_script (restrict permissions if you want)
>> > ./my_script args
>> >
>> > or put my_script in your PATH, and just type `my_script args'
>> >
>> > On Mon, Nov 24, 2008 at 4:47 PM, Jayson Williams
>> > <> wrote:
>> >> Hi All,
>> >>
>> >> I would like to do this -> my_script arg1, arg2
>> >> This doesn't seem to work when the script has arguments.
>> >>
>> >> But if I type -> ruby my_script arg1,arg2
>> >> It works fine.
>> >>
>> >> Is there a way I can run the my_script without typing ruby each time?
>> >> Thanks
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Diogo
>> >
>> >

>>
>>

> Yep, in Windows you have to invoke ruby first on the command line. The
> shebang in the Unix world is kind of a short hand for doing this.
>
> --
> "Hey brother Christian with your high and mighty errand, Your actions speak
> so loud, I can't hear a word you're saying."
>
> -Greg Graffin (Bad Religion)
>


If you absolutely must get rid of the need to type ruby first you could use
rubyscript2exe to build a windows exe file out of your script.

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

 
Reply With Quote
 
Kyle Schmitt
Guest
Posts: n/a
 
      11-24-2008
On Mon, Nov 24, 2008 at 3:12 PM, Jayson Williams
<> wrote:
> I am using win os, so the shabang thing isn't an option for me. I put
> the script in my ruby bin path, and I can access the script from
> anywhere now, but I still have the same problem with the script not
> running properly unless i type ruby first. It is as if ruby does not
> attempt to read in arguments unless you explicitly pass the script
> through ruby. If I call the script with the arguments without putting
> 'ruby' first, the args don't seem to get read.


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.

--Kyle

 
Reply With Quote
 
Glen Holcomb
Guest
Posts: n/a
 
      11-24-2008
[Note: parts of this message were removed to make it a legal post.]

On Mon, Nov 24, 2008 at 2:26 PM, Kyle Schmitt <>wrote:

> On Mon, Nov 24, 2008 at 3:12 PM, Jayson Williams
> <> wrote:
> > I am using win os, so the shabang thing isn't an option for me. I put
> > the script in my ruby bin path, and I can access the script from
> > anywhere now, but I still have the same problem with the script not
> > running properly unless i type ruby first. It is as if ruby does not
> > attempt to read in arguments unless you explicitly pass the script
> > through ruby. If I call the script with the arguments without putting
> > 'ruby' first, the args don't seem to get read.

>
> 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.
>
> --Kyle
>
>

And here I am forgetting the simple steps, doh!

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

 
Reply With Quote
 
Jayson Williams
Guest
Posts: n/a
 
      11-24-2008
The associations are correct. I reset them just to be sure though. I
can execute the script without ruby, and it runs, but without ruby
first, the args are not getting read.

The rubyscript2exe suggestion worked. Thanks Glen

Thanks everyone for the feedback

On Mon, Nov 24, 2008 at 4:18 PM, Glen Holcomb <> wrote:
> On Mon, Nov 24, 2008 at 2:21 PM, Glen Holcomb <> wrote:
>
>>
>>
>> On Mon, Nov 24, 2008 at 2:12 PM, Jayson Williams <
>> > wrote:
>>
>>> I am using win os, so the shabang thing isn't an option for me. I put
>>> the script in my ruby bin path, and I can access the script from
>>> anywhere now, but I still have the same problem with the script not
>>> running properly unless i type ruby first. It is as if ruby does not
>>> attempt to read in arguments unless you explicitly pass the script
>>> through ruby. If I call the script with the arguments without putting
>>> 'ruby' first, the args don't seem to get read.
>>>
>>>
>>> On Mon, Nov 24, 2008 at 2:05 PM, Diogo Lisboa <>
>>> wrote:
>>> > chmod a+x my_script (restrict permissions if you want)
>>> > ./my_script args
>>> >
>>> > or put my_script in your PATH, and just type `my_script args'
>>> >
>>> > On Mon, Nov 24, 2008 at 4:47 PM, Jayson Williams
>>> > <> wrote:
>>> >> Hi All,
>>> >>
>>> >> I would like to do this -> my_script arg1, arg2
>>> >> This doesn't seem to work when the script has arguments.
>>> >>
>>> >> But if I type -> ruby my_script arg1,arg2
>>> >> It works fine.
>>> >>
>>> >> Is there a way I can run the my_script without typing ruby each time?
>>> >> Thanks
>>> >>
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> > Diogo
>>> >
>>> >
>>>
>>>

>> Yep, in Windows you have to invoke ruby first on the command line. The
>> shebang in the Unix world is kind of a short hand for doing this.
>>
>> --
>> "Hey brother Christian with your high and mighty errand, Your actions speak
>> so loud, I can't hear a word you're saying."
>>
>> -Greg Graffin (Bad Religion)
>>

>
> If you absolutely must get rid of the need to type ruby first you could use
> rubyscript2exe to build a windows exe file out of your script.
>
> --
> "Hey brother Christian with your high and mighty errand, Your actions speak
> so loud, I can't hear a word you're saying."
>
> -Greg Graffin (Bad Religion)
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run os.execv() to run command pslq dbname < gen.command Sonu Python 2 08-04-2007 11:25 PM
Run Unix shell command $ parse command line arguments in python rkoida@yahoo.com Python 4 04-23-2005 04:42 AM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net 4 10-23-2003 11:09 AM
RUN/execute a Command-Line command from an ASP page Lucas Cowald ASP .Net Building Controls 1 10-22-2003 04:26 PM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net Datagrid Control 1 10-22-2003 12:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57