code: public static int execFromPath(final String command, final String[] parms, final OutputStream out,
              final DirectoryResource path) throws IOException
     {
        Assert.notNull(command, "Command must not be null.");
        Assert.notNull(path, "Directory path must not be null.");
        Assert.notNull(out, "OutputStream must not be null.");
        try
        {
           String[] commandTokens = parms == null ? new String[1] : new String[parms.length + 1];
           commandTokens[0] = command;
  
           if (commandTokens.length > 1)
           {
              System.arraycopy(parms, 0, commandTokens, 1, parms.length);
           }
  
           ProcessBuilder builder = new ProcessBuilder(commandTokens);
           builder.directory(path.getUnderlyingResourceObject());
           builder.redirectErrorStream(true);
           Process p = builder.start();
  
           InputStream stdout = p.getInputStream();
  
           Thread outThread = new Thread(new Receiver(stdout, out));
           outThread.start();
           outThread.join();
  
           return p.waitFor();
  
        }
        catch (InterruptedException e)
        {
           e.printStackTrace();
           return -1;
        }
     }
docs: Execute a native system command as if it were run from the given path.
  
  @param command the system command to execute
  @param parms the command parameters
  @param out a print writer to which command output will be streamed
  @param path the path from which to execute the command
  
  @return 0 on successful completion, any other return code denotes failure