United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8012453 : (process) Runtime.exec(String) fails if command contains spaces [win]

Details
Type:
Bug
Submit Date:
2013-04-17
Status:
Closed
Updated Date:
2013-12-17
Project Name:
JDK
Resolved Date:
2013-05-14
Component:
core-libs
OS:
Sub-Component:
java.lang
CPU:
Priority:
P2
Resolution:
Fixed
Affected Versions:
7u21
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Duplicate:
Duplicate:
Duplicate:
Relates:

Sub Tasks

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
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/5ea5f5dfb96a
User:  lana
Date:  2013-05-21 18:20:30 +0000

                                     
2013-05-21
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/5ea5f5dfb96a
User:  uta
Date:  2013-05-14 16:24:48 +0000

                                     
2013-05-14
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



Hardware and Software, Engineered to Work Together