-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0_04, 5.0
-
04
-
x86
-
windows_2000, windows_xp
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2062611 | 5.0 | Mark Reinhold | P2 | Resolved | Fixed | tiger |
JDK-2062610 | 1.4.2 | Mark Reinhold | P2 | Resolved | Fixed | b17 |
JDK-2062609 | 1.4.1_03 | Mark Reinhold | P2 | Resolved | Fixed | 03 |
Runtime.exec(String[]) does not correctly handle a command argument that
contains a space and ends with a backslash.
-- The following program demonstrates the problem
import java.io.*;
import java.util.*;
public class Cmd {
private static String getJavaCommand() {
String javaHome = System.getProperty("java.home");
if (javaHome != null && javaHome.length() > 0)
return (javaHome
+ File.separatorChar + "bin"
+ File.separatorChar + "java");
else
return "java";
}
public static void main(String[] args) throws Exception {
if (args.length > 0) {
System.err.println("child: " + args[0]);
return;
}
String[] cmd = new String[3];
cmd[0] = getJavaCommand();
cmd[1] = "Cmd";
cmd[2] = "foo bar\\baz\\";
System.err.println("parent: " + cmd[2]);
Process process = Runtime.getRuntime().exec(cmd);
InputStream in = process.getErrorStream();
byte[] buf = new byte[1024];
int n;
while ((n = in.read(buf)) >= 0)
System.out.write(buf, 0, n);
}
}
-- Expected output
parent: foo bar\bazchild: foo bar\baz
-- Actual output
parent: foo bar\bazchild: foo bar\baz"
contains a space and ends with a backslash.
-- The following program demonstrates the problem
import java.io.*;
import java.util.*;
public class Cmd {
private static String getJavaCommand() {
String javaHome = System.getProperty("java.home");
if (javaHome != null && javaHome.length() > 0)
return (javaHome
+ File.separatorChar + "bin"
+ File.separatorChar + "java");
else
return "java";
}
public static void main(String[] args) throws Exception {
if (args.length > 0) {
System.err.println("child: " + args[0]);
return;
}
String[] cmd = new String[3];
cmd[0] = getJavaCommand();
cmd[1] = "Cmd";
cmd[2] = "foo bar\\baz\\";
System.err.println("parent: " + cmd[2]);
Process process = Runtime.getRuntime().exec(cmd);
InputStream in = process.getErrorStream();
byte[] buf = new byte[1024];
int n;
while ((n = in.read(buf)) >= 0)
System.out.write(buf, 0, n);
}
}
-- Expected output
parent: foo bar\bazchild: foo bar\baz
-- Actual output
parent: foo bar\bazchild: foo bar\baz"
- backported by
-
JDK-2062609 (process) Arg with space and trailing backslash mangled (windows)
-
- Resolved
-
-
JDK-2062610 (process) Arg with space and trailing backslash mangled (windows)
-
- Resolved
-
-
JDK-2062611 (process) Arg with space and trailing backslash mangled (windows)
-
- Resolved
-
- relates to
-
JDK-4272706 Spaces in command-line parameters removed by Runtime.exec
-
- Resolved
-