Strange Win32 ARGV problem

Using the following one line ruby script (to dump out argv):
puts “ARGV:\n#{ARGV.join(”\n")}\n—"
I’m seeing VERY strange behavior with Ruby 1.8.0:

First, I’ll show that 4 different files exist in a local directory.

M:\builds\SYStest\eic\Yellow\products\EIC\src\attendant>dir
audiodetaildlg.*
Volume in drive M is WorkDrive3
Volume Serial Number is 90DB-A0F3

Directory of M:\builds\SYStest\eic\Yellow\products\EIC\src\attendant

09/04/2002 03:15 PM 3,817 AudioDetailDlg.cpp
03/25/2003 05:00 PM 1,498 AudioDetailDlg.h
2 File(s) 5,315 bytes
0 Dir(s) 6,820,958,208 bytes free

M:\builds\SYStest\eic\Yellow\products\EIC\src\attendant>dir audionode.*
Volume in drive M is WorkDrive3
Volume Serial Number is 90DB-A0F3

Directory of M:\builds\SYStest\eic\Yellow\products\EIC\src\attendant

08/01/2002 02:25 PM 3,409 AudioNode.cpp
07/31/2002 04:07 PM 1,849 AudioNode.h
2 File(s) 5,258 bytes
0 Dir(s) 6,820,958,208 bytes free

Now, I’ll run the script that dumps out argv and pass it some wildcard
arguments which should match these files.

M:\builds\SYStest\eic\Yellow\products\EIC\src\attendant>ruby bs.rb test
AudioDetailDlg.* AudioNode.*
ARGV:
test
AudioDetailDlg.* AudioNode.*

···

Huh? Why did the two arguments get passed in as one argument to argv !?
This is causing some of my scripts serious problems. :frowning:

M:\builds\SYStest\eic\Yellow\products\EIC\src\attendant>ruby bs.rb test
AudioDetailDlg.*
ARGV:
test
AudioDetailDlg.cpp
AudioDetailDlg.h

Hmmm… now it performed wildcard expansion and put the two files as
separate arguments.
Basically, the first option after a wildcard argument gets grouped in
with that wildcard parameter as a single argument and the expansion
doesn’t occur.

M:\builds\SYStest\eic\Yellow\products\EIC\src\attendant>ruby bs.rb test
AudioDetailDlg.* foo AudioNode.*
ARGV:
test
AudioDetailDlg.* foo
AudioNode.cpp
AudioNode.h

Cheers…
Patrick Bennett

Patrick: please note that you are apparently HTML format messages,
which makes it hard to read what you have written. (This is why I
haven’t quoted anything from you – the formatting was too badly
messed up.)

In answer to your question, you have been bitten by a significant
difference between the way that Unix and Windows command lines work.
When you do a “*” in Unix, the SHELL (bash, zsh, etc.) expands the
directory entries for you … even if you don’t want it to do so.[1]
On Windows, however, that responsibility lies exclusively with the
program.

In Windows, you’ll need to use the patterns you have been given with
the Dir#[] method.

-austin

···


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.10.02
* 18.32.04