FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Passing arguments to a process via Runtime.exec(cmd[]), any arguments with quotes (") around them lose the quotes if the String starts with a whitespace. See the steps to reproduce.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following simple classes reproduce:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RunMe
{
public static void main(String[] args)
throws Exception
{
String[] commandArray =
{
"java",
"-classpath",
".",
"PrintArgs",
" \"arg 1\"",
};
Process p = Runtime.getRuntime().exec(commandArray);
StringBuffer stdout = new StringBuffer();
InputStreamReader isr = new InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
{
stdout.append(line+"\n");
}
System.out.println(stdout);
}
}
//------------------------------
public class PrintArgs
{
public static void main(String[] args)
{
for (int i = 0; i < args.length; i++)
{
System.out.println("args["+i+"] = [" + args[i] + "]");
}
}
}
Observe the the last parameter in commandArray is surrounded by quotes and has a space in front of it.
The output of running RunMe is:
args[0] = [ arg]
args[1] = [1]
The quotes are getting lost. Removing the space in front of arg1 changes the output to this:
args[0] = [arg 1]
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Make sure you don't put spaces in front of your arguments :-)
###@###.### 2005-05-26 13:37:40 GMT
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Passing arguments to a process via Runtime.exec(cmd[]), any arguments with quotes (") around them lose the quotes if the String starts with a whitespace. See the steps to reproduce.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following simple classes reproduce:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RunMe
{
public static void main(String[] args)
throws Exception
{
String[] commandArray =
{
"java",
"-classpath",
".",
"PrintArgs",
" \"arg 1\"",
};
Process p = Runtime.getRuntime().exec(commandArray);
StringBuffer stdout = new StringBuffer();
InputStreamReader isr = new InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
{
stdout.append(line+"\n");
}
System.out.println(stdout);
}
}
//------------------------------
public class PrintArgs
{
public static void main(String[] args)
{
for (int i = 0; i < args.length; i++)
{
System.out.println("args["+i+"] = [" + args[i] + "]");
}
}
}
Observe the the last parameter in commandArray is surrounded by quotes and has a space in front of it.
The output of running RunMe is:
args[0] = [ arg]
args[1] = [1]
The quotes are getting lost. Removing the space in front of arg1 changes the output to this:
args[0] = [arg 1]
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Make sure you don't put spaces in front of your arguments :-)
###@###.### 2005-05-26 13:37:40 GMT
- duplicates
-
JDK-6511002 (process) Document the auto-quoting when creating a Windows process; add winQuote
- Closed
- relates to
-
JDK-6214916 -version:<id> argument affects application arguments containing spaces
- Closed
-
JDK-6468220 (process) Runtime.exec(String[]) does not pass command line arguments correctly (win)
- Closed
-
JDK-4230619 (process) Need access to unparsed command line arguments
- Closed