edit this page - page history - about editing

Runtime.exec returns -1073741515 when providing environment variables


I was having a problem where using Runtime.exec(String[]) would work fine, but using Runtime.exec(String[], String[]) would return the value -1073741515.

After a bit of digging, it turns out that the -1073741515 return value may mean STATUS_DLL_NOT_FOUND within Windows.

Using Process Monitor, I added a filter to check for the target .exe and found that it was failing to load cygwin1.dll:

The problem is that Runtime.exec(String[], String[]) does not copy over any existing environment variables, whereas Runtime.exec(String[]) does. You therefore have to copy existing environment variables yourself:

protected String[] getEnvironmentVariables() {
  List<String> envp = new ArrayList<String>();
  for (String key : System.getenv().keySet()) {
    envp.add(key + "=" + System.getenv(key));

  // add your environment variable here

  // return as a list of strings
  return envp.toArray(new String[]{});

(In this case, the PATH variable was not being provided, so it couldn't find the cygwin1.dll anywhere.)
Categories: Java
edit this page - what links to here? - page history - top
Last edited by jevon jevon 77 months ago