dcsimg

How do I change the starting directory for running a command with ProcessBuilder?

John Zukowski

Use the directory() method of ProcessBuilder to change the starting / working directory. Once setting the directory, start() the sub-process.


   ProcessBuilder processBuilder = new ProcessBuilder(
                                       command, arg1, arg2);
   processBuilder.directory("DirectoryLocation");
   Process p = processBuilder.start();