A DESCRIPTION OF THE REQUEST :
I have a program that uses IrfanView to resize some images (see #4924909 to understand why I'm not resizing them in Java), but I discovered that ProcessImpl automatically add quotes around any element of the command array that has spaces, but doesn't already begin and end with quote marks (it gives an IllegalArgumentException if the element begins with a quote mark but doesn't end with one).
JUSTIFICATION :
This is sometimes handy, and should be documented, but some external programs (such as IrfanView) expect a quoted path as part of a parameter, but don't handle it properly if the parameter itself is quoted.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Ability to create a command line such as:
"c:\program files\irfanview\i_view32.exe" "image 1.jpg" /convert="image 2.jpg" /resize=(100,100)
ACTUAL -
Command line becomes:
"c:\program files\irfanview\i_view32.exe" "image 1.jpg" "/convert="image 2.jpg"" /resize=(100,100)
and IrfanView gives an error that it failed to load 'image 1.jpg"' (error dialog included double-quote at end, but didn't actually include the single quotes)
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) {
try {
Runtime.getRuntime().exec(new String[] {"c:\program files\irfanview\i_view32.exe", "image 1.jpg", "/convert=\"image 2.jpg\"", "/resize=(100,100)"});
} catch (IOException e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
(1) For IrfanView, put the resize parameter before the convert parameter.
(2) Pre-tokenize the parameter that you don't want auto-quoted (e.g. "/convert=\"image", "2.jpg\"") -- this is annoying and would not allow inserting a tab character into such a parameter.
I have a program that uses IrfanView to resize some images (see #4924909 to understand why I'm not resizing them in Java), but I discovered that ProcessImpl automatically add quotes around any element of the command array that has spaces, but doesn't already begin and end with quote marks (it gives an IllegalArgumentException if the element begins with a quote mark but doesn't end with one).
JUSTIFICATION :
This is sometimes handy, and should be documented, but some external programs (such as IrfanView) expect a quoted path as part of a parameter, but don't handle it properly if the parameter itself is quoted.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Ability to create a command line such as:
"c:\program files\irfanview\i_view32.exe" "image 1.jpg" /convert="image 2.jpg" /resize=(100,100)
ACTUAL -
Command line becomes:
"c:\program files\irfanview\i_view32.exe" "image 1.jpg" "/convert="image 2.jpg"" /resize=(100,100)
and IrfanView gives an error that it failed to load 'image 1.jpg"' (error dialog included double-quote at end, but didn't actually include the single quotes)
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) {
try {
Runtime.getRuntime().exec(new String[] {"c:\program files\irfanview\i_view32.exe", "image 1.jpg", "/convert=\"image 2.jpg\"", "/resize=(100,100)"});
} catch (IOException e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
(1) For IrfanView, put the resize parameter before the convert parameter.
(2) Pre-tokenize the parameter that you don't want auto-quoted (e.g. "/convert=\"image", "2.jpg\"") -- this is annoying and would not allow inserting a tab character into such a parameter.
- duplicates
-
JDK-6276512 (process) Runtime.exec(cmd[]) ignores quotes around arguments (win)
- Closed
-
JDK-6550942 (process) Runtime.exec(String,String[],File) incorrectly handles quotes
- Closed
-
JDK-7032109 ProcessBuilder incorrectly deals with quoted parameters
- Closed
- relates to
-
JDK-6468220 (process) Runtime.exec(String[]) does not pass command line arguments correctly (win)
- Closed
-
JDK-6518827 (process) zero length Process arguments ignored on win32
- Closed