JDK-8012453 : (process) Runtime.exec(String) fails if command contains spaces [win]
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7u21
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-04-17
  • Updated: 2017-05-17
  • Resolved: 2013-05-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7 JDK 8
5.0u51Fixed 6u51Fixed 7u25Fixed 8 b91Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
1.7.0_21 64 bit

ADDITIONAL OS VERSION INFORMATION :
Windows 7 [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Process p = exec(  " F:\\Program Files\
etload\
etload.exe " );
fails
The command works fine from the command line, or in 1.7.0_17

However
Process p = exec(  " E:\\sys\
etload.exe " );

works fine in 1.7.0_21 if I put a copy of netload.exe in E:\sys

exec no longer likes spaces in filenames.

REGRESSION.  Last worked in version 7u17

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
put snippets in a dummy program.  Run them both ways with some exe that does exist on your Windows machine.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should work either way
ACTUAL -
Only exe without space in filenames can be execed.


REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
move files to directories without spaces in the names.
Comments
verified in b94
2013-06-17

The nightly test run hasn't completed yet. But among the competed tasks there are no failures that could be caused by the fix. So, SQE is OK to take the fix into the June CPU.
2013-05-14

A fix for this is currently in review here: http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-April/016302.html
2013-04-25

The 7u21 release notes reads: "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."
2013-04-17