在Eclipse中运行Java应用程序时如何避免全局扩展 [英] How to avoid glob expansion when running a Java app in Eclipse
问题描述
我遇到了Eclipse运行配置的特殊行为,这似乎是仅Windows的问题.假设我有一个Java应用程序,可以打印出命令行参数,如下所示:
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);
}
}
}
如果我为参数提供可以由shell扩展的通配符,则shell将对其进行扩展并将其提供给Java程序.这不足为奇.所以,如果我在命令提示符下这样做
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/*
程序将打印
test/foo.txt
test/bar.txt
其中foo.txt和bar.txt是目录"test"中的文件.
where foo.txt and bar.txt are files in the directory "test".
如果我在引号中加上通配符,则可以防止Shell扩展.* nix上的单引号,Windows上的双引号.因此,对于Windows,如果我在命令提示符下执行以下操作:
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/*"
该程序现在将打印
test/*
(不扩展).
但是,我发现Eclipse运行启动器中的引用似乎没有任何作用,并且该参数仍在扩展.如果我放
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/*"
在Eclipse运行启动器的程序参数部分中,并运行上面的类,我仍然得到
in the program argument section in the Eclipse run launcher, and run the above class, I still get
test/foo.txt
test/bar.txt
换句话说,当程序实际运行时,双引号似乎丢失了.这似乎仅在Windows中发生.
In other words, the double quotes seem to be lost when the program actually runs. This seems to happen only with Windows.
是否有一种方法可以防止Windows上的Eclipse运行启动器扩展全局扩展?
Is there a way to prevent the glob expansion with the Eclipse run launcher on Windows?
推荐答案
(.*)
模式不会被eclipse扩展,并且仍然可以作为正则表达式使用.
The pattern (.*)
will not be expanded by eclipse, and still works as a regex.
这篇关于在Eclipse中运行Java应用程序时如何避免全局扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!