Search code examples
java-7

Java 7u25 allowAmbigousCommands property not working


Java system property allowAmbigousCommands is not working for me on Windows 7, 7u25 32b JRE:

System.setProperty("jdk.lang.Process.allowAmbigousCommands", "true");
try {
    Process p= Runtime.getRuntime().exec("foo.bat > myOutput.txt");
} catch (IOException e) {
    e.printStackTrace();
}

where the content of foo.bat is:

echo "hello world"

I've also checked using -Djdk.lang.Process.allowAmbigousCommands=true with no success. Any clue?

Thanks in advance.


Solution

  • jdk.lang.Process.allowAmbigousCommands won't help with batch file executions.

    Run exec() as

    Runtime.getRuntime().exec("cmd /C \"foo.bat > myOutput.txt\"");
    

    Reference :
    JDK 7u25: Solutions to Issues caused by changes to Runtime.exec()