File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Windows cmd line args with wildcards Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Windows cmd line args with wildcards" Watch "Windows cmd line args with wildcards" New topic
Author

Windows cmd line args with wildcards

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 170

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

Joined: Oct 02, 2003
Posts: 10916
    
  12



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

C:\slop>


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
It works just the same on Linux as on Windows.
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 170

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

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Oct 27, 2005
Posts: 19543
    
  16

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Windows cmd line args with wildcards
 
Similar Threads
* as a parameter to main
OO Calculator -- a Tutorial
Someone can explain this? Why Output is so strange?
asterisk program possible to do in module way
Asterisk as a command-line argument