How to change the current working directory in Groovy

Joe picture Joe · Aug 12, 2013 · Viewed 36.3k times · Source

Now, I am writting a Groovy script to invoke other's interface. But I need change my current working path when running the script. I know it is not possible in Java. Is it possible in Groovy?

Answer

kirill-a picture kirill-a · May 18, 2016

If you can run other script as separate process, you can give ProcessBuilder parameter working dir:

def processBuilder=new ProcessBuilder(command)
processBuilder.directory(new File("Working dir"))
def process = processBuilder.start()

or

command.execute(null, new File("Working dir"))

so that process will switch to your new folder and execute it there.