Runtime.exec() produces errors on WindowsNT/2000. The same arguments, that works correctly in JDK 1.3.1 do not work in JDK 1.4.0 beta 73. On Unix systems the functionality is O.K. in all JDK versions.
When I have following String:
execStr = cmd /X /C "cd /D \"c:\Program Files\""
Runtime.getDefault().exec(execStr) gives following exception:
java.lang.IllegalArgumentException: "cd: unmatched quotes.
at java.lang.Win32Process.<init>(Win32Process.java:57)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:551)
at java.lang.Runtime.exec(Runtime.java:418)
at java.lang.Runtime.exec(Runtime.java:361)
at java.lang.Runtime.exec(Runtime.java:325)
at TestExec.main(TestExec.java:32)
When I parse the String into the String[] array in the following way:
cmd
/X
/C
cd /D \"c:\Program Files\"
and call: Runtime.getDefault().exec(execArr), the command executes, but I get following error on the error output:
The name specified is not recognized as an
internal or external command, operable program or batch file.