how to avoid glob expansion when running Java app in eclipse

孤人 提交于 2019-12-04 03:08:07

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/3861086/how-to-avoid-glob-expansion-when-running-java-app-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!