This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Windows cmd line args with wildcards  RSS feed

 
Saloon Keeper
Posts: 4797
52
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?
 
lowercase baba
Bartender
Posts: 12627
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

C:\slop>
 
Marshal
Posts: 60199
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works just the same on Linux as on Windows.
 
Carey Brown
Saloon Keeper
Posts: 4797
52
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
Marshal
Posts: 60199
188
  • 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.
 
Sheriff
Posts: 21462
96
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
Boost this thread!