[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting command line

Joe Van Dyk

9/30/2006 12:42:00 AM

Hi,

If I launch a Ruby process with:
ruby something.rb lots of "stuff here" and I want all 'of it'

How can I get a string from inside the ruby process with:
lots of "stuff here" and I want all 'of it'
in it?

4 Answers

Tim Hunter

9/30/2006 12:55:00 AM

0

Joe Van Dyk wrote:
> Hi,
>
> If I launch a Ruby process with:
> ruby something.rb lots of "stuff here" and I want all 'of it'
>
> How can I get a string from inside the ruby process with:
> lots of "stuff here" and I want all 'of it'
> in it?
>
ARGV is an array of the tokens on the command line that follow the name
of the script. If you want them all in one string you can use the join
method to join them together.

puts ARGV.join(' ')


Ara.T.Howard

9/30/2006 2:52:00 AM

0

Hal E. Fulton

9/30/2006 3:53:00 AM

0

Timothy Hunter wrote:
> Joe Van Dyk wrote:
>
>> Hi,
>>
>> If I launch a Ruby process with:
>> ruby something.rb lots of "stuff here" and I want all 'of it'
>>
>> How can I get a string from inside the ruby process with:
>> lots of "stuff here" and I want all 'of it'
>> in it?
>>
> ARGV is an array of the tokens on the command line that follow the name
> of the script. If you want them all in one string you can use the join
> method to join them together.
>
> puts ARGV.join(' ')
>

Of course, if you (the OP) want the quotes, you'll have to escape
them or the shell will strip them.


Hal


Joe Van Dyk

10/2/2006 4:25:00 PM

0

On 9/29/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Sat, 30 Sep 2006, Joe Van Dyk wrote:
>
> > Hi,
> >
> > If I launch a Ruby process with:
> > ruby something.rb lots of "stuff here" and I want all 'of it'
> >
> > How can I get a string from inside the ruby process with:
> > lots of "stuff here" and I want all 'of it'
> > in it?
>
> you can't. the " and ' are handled by the shell.
>
> ARGV.join will give you
>
> [ "lots", "of" "stuff here", "and", "I", "want", "all", "of it"]
>
> note - the quotes will be lost.
>
> read up on bash 'word splitting' and 'quote removal' for more info
>
> http://www.gnu.org/software/bash/manual/bashref....
> http://www.gnu.org/software/bash/manual/ba...
>
> regards.

Oh yeah, I forgot that the shell automatically escapes stuff. Thanks.