Duplicate :
|
FULL PRODUCT VERSION : java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07) Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows [Version 6.1.7601] EXTRA RELEVANT SYSTEM CONFIGURATION : 64 Bit A DESCRIPTION OF THE PROBLEM : ProcessBuilder is unable to deal with quoted parameters. Some EXEs expect to get parameters with quotes inside parameters. Example: SOME.EXE -A="Path With Blanks" ProcessBuilder wants to quote blanks, but expects that it must put quote characters around the complete parameter (i. e. "-A=Path With Blanks"). The problem is that some EXEs expect that quotes INSIDE the parameter instead (i. e. -A="Path With Blanks"). Even if correctly provided as a ready-to-use String, ProcessBuilder screws this, because it doesn't check for quotes existing already WITHIN the parameter and adds even more quotes, i. e. it internally does "-A="Path With Blanks"" which is totally wrong as a typical EXE now thinks it receives multiple parameters, i. e. "-A" and "Path With Blanks" -- but least EXEs would accept that. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : ProcessBuilder p = new ProcessBuilder("SOME.EXE"); p.command().add("-A=\"Path with blank\""); // Already quoted, keep hands off! p.start(); EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - ProcessBuilder must see that there already are quotes INSIDE the parameter, so it should keep its hand off and not try to provide any additional quoting. ACTUAL - ProcessBuilder ignores the already existing quotes and adds another pair of quotes, i. e. it does two parameters, first is "-A", second is "Path with blank", which is totally wrong. ERROR MESSAGES/STACK TRACES THAT OCCUR : Executed process will be unable to find "Path with blank", as the calling process (a) expects the particular syntax having quotes WITHIN the first parameter and (b) expects to only get one parameter but not two. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- ProcessBuilder p = new ProcessBuilder("SOME.EXE"); p.command().add("-A=\"Path with blank\""); p.start(); ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Copy the file to a path that has no blanks and rename the file to a blank-free name. The workaround is not working in some cases, as on Windows 7 you can only write to few paths like TEMP and USERPROFILE. The problem is that these paths already can have blanks. So there might be no writeable path having no blanks. This is a showstopper bug as it might be impossible to find a solution depending on the actual Windows 7 configuration!