Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Windows cmd line args with wildcards

 
Carey Brown
Bartender
Posts: 1945
24
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This shouldn't be this difficult. I want to pass a wildcard expression to my Java program WITHOUT having cmd.exe expand the argument to a list of files/directories. E.g. something like: java Program "*.java" where I want the asterisk-dot-java to come through as a single command line argument. I've tried the back-slash character and the caret to escape the asterisk, but no luck. What does Microsoft want from me?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12265
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


C:\slop>java Test "*.java"
*.java

C:\slop>
 
Campbell Ritchie
Sheriff
Posts: 51418
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works just the same on Linux as on Windows.
 
Carey Brown
Bartender
Posts: 1945
24
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I tried the code I get:
abc.java
xyz.java
(etc.)

Ah, there is a catch, IF there are actual java files in my current working directory I get the aforementioned list, ELSE IF there are NO java files in my CWD then I do get the literal "*.java" as my argument. I'm assuming this is a Microsoft'ism (XP). I never had this problem on UNIX.

P.S., mine was
 
Campbell Ritchie
Sheriff
Posts: 51418
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesterday, I wrote:It works just the same on Linux as on Windows.
. . . and today I see it is different on Windows. No idea why. Sorry.
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Ah, there is a catch, IF there are actual java files in my current working directory I get the aforementioned list, ELSE IF there are NO java files in my CWD then I do get the literal "*.java" as my argument. I'm assuming this is a Microsoft'ism (XP). I never had this problem on UNIX.

I also don't have that problem on my Windows 7 machine:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic