ARGV problems

  • Thread starter tony summerfelt
  • Start date
T

tony summerfelt

i seem to be having a problem with ARGV.

something as simple as this:


ARGV.each {|x| print "#{x}"}

prints: %*

regardless of how many arguments i use.

what's the proper way of getting commandline arguments. i was hoping to
keep the code down by not using getoptlong, but i'll use it if necessary
 
M

Mike Stok

i seem to be having a problem with ARGV.

something as simple as this:


ARGV.each {|x| print "#{x}"}

prints: %*

regardless of how many arguments i use.

what's the proper way of getting commandline arguments. i was hoping to
keep the code down by not using getoptlong, but i'll use it if necessary

Is that your entire code?

[mike@ratdog tmp]$ cat try.rb
#!/usr/bin/env ruby

ARGV.each {|x| puts "#{x}"}
[mike@ratdog tmp]$ ./try.rb foo bar baz
foo
bar
baz
[mike@ratdog tmp]$

Mike
 
G

Gennady

I would make a wild guess that you call your ruby script from a shell
script trying to pass it all command line parameters the sell script has
been called with. In a shell script $* stands for the entire command
line, and it seems like you do %* instead.

However if you use .bat files on Windows, where %* is a correct way to
specify all parameters, than it beats me.

Gennady.
 
T

tony summerfelt

Is that your entire code?
ARGV.each {|x| puts "#{x}"}


yup.

i AM using the new windows installer version of ruby (v1.8.1 (2004-01-07)
that was just announced.

[checking older version (2004-01-27)].

ah ha...older version works fine...

i'd guess there's something seriously wrong with the installer version :/
 
T

tony summerfelt

I would make a wild guess that you call your ruby script from a shell
script trying to pass it all command line parameters the sell script has i


this was all from the command line.


on further investigation, my command shell is 4nt (nt version of 4dos) and
just typing the program: argtest.rb aa bb

using a batch file it ran ok.

if i use the direct path to ruby g:\ruby\bin\ruby argtest.rb aa bb it
works fine also...
 
N

nobu.nokada

Hi,

At Wed, 4 Feb 2004 07:15:04 +0900,
tony said:
on further investigation, my command shell is 4nt (nt version of 4dos) and
just typing the program: argtest.rb aa bb

Do you associate .rb to "g:\ruby\bin\ruby.exe %0 %*"? If so,
does 4nt really expand %* in associated command lines?
 
T

tony summerfelt

Do you associate .rb to "g:\ruby\bin\ruby.exe %0 %*"?

yes, actually i use .rb="g:\ruby\bin\ruby.exe" and i had a typo

now of course it works :/

that should be the last of the dumb questions i ask...for awhile.. :)
 

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,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top