I'm trying to run a batch script on windows using groovy. I started with this code:
StringBuilder output = new StringBuilder()
StringBuilder error = new StringBuilder()
dir = new File("$homedir")
Process proc = "pathToScript\script.bat --arg test".execute(null, dir)
proc.consumeProcessOutput(output, error)
proc.waitFor()
print proc.exitValue()
This code works just fine for my scripts, but some commands don't play nice, so I decided to start using an ArrayList to store the arguments. So now my code looks like this:
StringBuilder output = new StringBuilder()
StringBuilder error = new StringBuilder()
dir = new File("$homedir")
ArrayList command = ["pathToScript\script.bat", "--arg test"]
Process proc = command.execute(null, dir)
proc.consumeProcessOutput(output, error)
proc.waitFor()
print proc.exitValue()
Now for some inexplicable reason it runs script.bat without the arguments. I've printed out the list to be sure it contains the arguments properly, which it does, so I'm not sure why the execute method isn't using them.