views:

99

answers:

2

I am running into a peculiar behavior of the eclipse run configuration, and it appears to be a Windows-only problem. Suppose I have a Java app that prints out the command line arguments, like the following:

public class WildCard {
    public static void main(String[] args) {
        for (String arg: args) {
            System.out.println(arg);
        }
    }
}

If I provide argument with a wild card that can be expanded by the shell, the shell will expand it and give it to the Java program. That's no surprise. So, if I do on the command prompt

java WildCard test/*

the program will print

test/foo.txt
test/bar.txt

where foo.txt and bar.txt are files in the directory "test".

Shell expansions can be prevented if I surround the wildcard argument in quotes; single quotes on *nix, and double quotes on Windows. So for Windows, if I do the following on the command prompt:

java WildCard "test/*"

the program will now print

test/*

(no expansion).

However, what I find is that the quoting in the eclipse run launcher seems to have no effect, and the argument is still expanded. If I put

"test/*"

in the program argument section in the eclipse run launcher, and run the above class, I still get

test/foo.txt
test/bar.txt

In other words, the double quotes seem to be lost when the program actually runs. This seems to happen only with Windows.

Is there a way to prevent the shell expansion with the eclipse run launcher on Windows? Thanks!

A: 

Escape the quotes at the application args:

\"doc/*\"

I have checked it and it kind of work. Output:

"doc/*"

(Note that it is printing the quotes also)

Tomas Narros
Yes, I tried that and found the same result. What I need is the original string, so it doesn't quite meet the need...
sjlee