如何在cygwin中的windows下的bash中调用java.exe,路径中带有空格
我尝试使用 cygwin 在 Windows (Win XP) 上的 bash 脚本中调用 java。 但是 java.exe 的路径包含空格。
仅从字面上将类似这样的东西放入 bash 中才有效:
/cygdrive/c/Program\ Files/Java/jdk1.5.0_10/bin/java -cp "$TOOL_HOME" DateParse "$DATE" "$FORMAT"
我将 java 路径放入变量的尝试失败了:
export JAVA_EXE="/cygdrive/c/Program\ Files/Java/jdk1.5.0_10/bin/java"
$JAVA_EXE -cp "$TOOL_HOME" DateParse "$DATE" "$FORMAT"
与 cygpath、引号、括号的不同组合也不起作用。我没有找到合适的组合
I tried to invoke java inside bash script on windows (Win XP) using cygwin.
However path to java.exe contain spaces.
only literaly putting in bash sometghing like this worked:
/cygdrive/c/Program\ Files/Java/jdk1.5.0_10/bin/java -cp "$TOOL_HOME" DateParse "$DATE" "$FORMAT"
My attemts to put java path to a variable failed:
export JAVA_EXE="/cygdrive/c/Program\ Files/Java/jdk1.5.0_10/bin/java"
$JAVA_EXE -cp "$TOOL_HOME" DateParse "$DATE" "$FORMAT"
also different combination with cygpath, quotes, brackets did not work. I am not finding the the right combination
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
$JAVA_EXE
周围加上引号:问题是,每次扩展变量时,它也会在空格处分解为单词,除非您在它周围加上引号。因此,如果您不希望内容在空格处被破坏,则需要引号。
另一种选择是始终使用不允许空格的短 (DOS) 名称。要查看短名称是什么,请运行
将其转换回类似 UNIX 的 cygwin 路径,使用
Put quotes around
$JAVA_EXE
:The problem is that every time a variable is expanded, its also broken into words at spaces, UNLESS you put quotes around it. So if you don't want things broken at spaces, you need quotes.
Another alternative is to always use short (DOS) names for things, which don't allow spaces. To see what the short name is, run
to convert that back to a unix-like cygwin path, use
谢谢你的想法。它以适当的组合发挥作用。问题是我正在转义空格字符,同时将 JAVA_EXE 放在引号中。
产生这种效果:
另一方面,转换为 DOS 8.3 也不起作用:
\bin\java
最后,将 JAVA_EXE 放在引号中,但不转义路径中的空格对我来说效果很好:
thank you for your ideas. It worked in proper combination. The issue was that I was escaping space character and at the same time putting JAVA_EXE in quotes.
produce this effect:
on the other hand, converting to DOS 8.3 does not work neither:
\bin\java
Finally, putting JAVA_EXE in quotes but without escaping space in path worked fine for me: