Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid glob expansion when running a Java app in Eclipse

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?

like image 950
sjlee Avatar asked Mar 02 '26 09:03

sjlee


1 Answers

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

like image 110
kleidt Avatar answered Mar 03 '26 23:03

kleidt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!