12

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 glob expansion with the Eclipse run launcher on Windows?

5
  • I am inclined to believe this is a bug with eclipse, but wanted to see if there is a viable workaround to the problem.
    – sjlee
    Oct 5, 2010 at 16:16
  • My suggestion of escaping the wildcard with backslashes does not really work. It does work in the test case I used (and I still don't know why) but not in other cases. I am deleting my answer since it is not actually solving the problem.
    – Grodriguez
    Oct 5, 2010 at 16:42
  • 4
    I found an existing eclipse bug on this... goo.gl/eM6e
    – sjlee
    Oct 5, 2010 at 17:03
  • I'm wondering where does the launcher 'java' process the wildcard expanding. I could not find it in the source code of jdk. Sep 9, 2014 at 2:56
  • I'm using IntelliJ IDEA, but I found this article helpful, mindprod.com/jgloss/wildcard.html
    – James
    Jun 30, 2015 at 3:57

2 Answers 2

0

The problem looks quite wired:

*.txt
foo.*

will NOT be expanded, but

*
*.*
"*"
"*.*"
\"*\"
\"*.*\"

will be expanded.

It looks like only "all files" is expanded, but all other strings (including *) will stay unchanged.

I'm at the same problem and I use XP and eclipse 3.5.2

0

The pattern (.*) will not be expanded by eclipse, and still works as a regex.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.