Executable name has embedded quote, split the arguments

将JDK升级到7u21后,一个应用的内置Tomcat启动不了,报出 Executable name has embedded quote, split the arguments 的错误。

经过查询发现 jdk 7u21 和 jdk 6u 45的改变了Runtime.exec方法实现。对含有空格的命令会有影响。


Changes to Runtime.exec

On Windows platform, the decoding of command strings specified to Runtime.exec(String), Runtime.exec(String,String[]) and Runtime.exec(String,String[],File) methods, has been improved to follow the specification more closely. This may cause problems for applications that are using one or more of these methods with commands that contain spaces in the program name, or are invoking these methods with commands that are not quoted correctly.

For example, Runtime.getRuntime().exec("C:\\My Programs\\foo.exe bar") is an attempt to launch the program "C:\\My" with the arguments "Programs\\foo.exe" and "bar". This command is likely to fail with an exception to indicate "C:\My" cannot be found.

The example Runtime.getRuntime().exec("\"C:\\My Programs\\foo.exe\" bar") is an attempt to launch the program "\"C:\\My". This command will fail with an exception to indicate the program has an embedded quote.

Applications that need to launch programs with spaces in the program name should consider using the variants of Runtime.exec that allow the command and arguments to be specified in an array.

Alternatively, the preferred way to create operating systems processes since JDK 5.0 is using java.lang.ProcessBuilder. The ProcessBuilder class has a much more complete API for setting the environment, working directory and redirecting streams for the process.


参考资料

[1] Java™ SE Development Kit 6, Update 45 (JDK 6u45) Update Release Notes. http://www.oracle.com/technetwork/java/javase/6u45-relnotes-1932876.html
[2] Java™ SE Development Kit 7, Update 21 (JDK 7u21) Update Release Notes.  http://www.oracle.com/technetwork/java/javase/7u21-relnotes-1932873.html
[3] exec problem is JDK 1.7.0_21. http://www.velocityreviews.com/forums/t959814-exec-problem-is-jdk-1-7-0_21-a.html


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值