Reputation: 303
I'm running a Perl script (MOSS, Measure of Software Similarity) that uploads either a file or a folder of files to a server, but I'm running into some weird behaviors.
This is supposed to work:
mossnet.pl -l java -d Files/*/*.java
However, when I try that, I'm told Files//.java does not exist (but it does).
But when I instead direct it to a specific file in that directory:
mossnet.pl -l java -d Files/foo/bar.java Files/foo2/bar2.java
It works correctly. So, it's able to see the directory structure, but it seems to trip when it's given wildcards.
Any suggestions?
If relevant: I'm on a PC, Windows 7.
Upvotes: 0
Views: 658
Reputation: 118645
Yes, it's relevant that you're on Windows. Wildcard expansion in the Windows shell is buggy and the docs recommend (and provide a technique) to handle them yourself:
http://search.cpan.org/dist/perl-5.23.2/README.win32#Command-line_Wildcard_Expansion
The default command shells on DOS descendant operating systems (such as they are) usually do not expand wildcard arguments supplied to programs. They consider it the application's job to handle that. This is commonly achieved by linking the application (in our case, perl) with startup code that the C runtime libraries usually provide. However, doing that results in incompatible perl versions (since the behavior of the argv expansion code differs depending on the compiler, and it is even buggy on some compilers). Besides, it may be a source of frustration if you use such a perl binary with an alternate shell that does expand wildcards.
Instead, the following solution works rather well. The nice things about it are 1) you can start using it right away; 2) it is more powerful, because it will do the right thing with a pattern like //*.c; 3) you can decide whether you do/don't want to use it; and 4) you can extend the method to add any customizations (or even entirely different kinds of wildcard expansion).
# Wild.pm - emulate shell @ARGV expansion on shells that don't
use File::DosGlob;
@ARGV = map {
my @g = File::DosGlob::glob($_) if /[*?]/;
@g ? @g : $_;
} @ARGV;
1;
To use this, you would do something like
C:\> set PERL5OPT=-MWild
C:\> mossnet.pl -l java -d Files/*/*.java
or
C:\> perl -MWild mossnet.pl -l java -d Files/*/*.java
(or you could put the above code at the beginning of your script)
Upvotes: 3
Reputation: 1933
Multiple wild cards in the path, like
Files/*/*.java
may not be supported in some basic versions of Windows shell cmd.exe
You may want to try using Power shell or some other shell like Cygwin for this functionality
Try
dir Files/*/*.java
or some other command like ls or type in the shell to see if it supports this.
Upvotes: 1