gradle-plugins
gradle-plugins copied to clipboard
Exec plugin: Command string with spaces does not work on mac os x
Tried using this today to execute a command on Mac OS X. It only works when the command string does not contain spaces. The example did not work..."ls -al" where "ls" does. I believe this has to do with how Java treats the command line string when passed in as an array. i.e. if running with Java directly
Runtime.getRuntime().exec("ls -al", null, new File("
This does not work. However, if the array is broken up as follows
Runtime.getRuntime().exec("ls, "-al", null, new File("
This does work. It works because the method being called is expecting a string array that is already broken up into tokens that are the command followed by the arguments.
ExecPlugin.groovy: Line 13
project.execIn(baseDir, cmd)
I think if cmd is split on spaces at this point it will fix the issue.
What if people want to pass a command that contains spaces?
Do you mean that, perhaps, the command has spaces in it's path like this?
C:/Command Path/command
I think this is ok, but in this case the best approach would be to separate the command from the arguments from the get go, and not use a single string for the command and arguments like this.
C:/Command Path/command -arg1 -arg2 arg3
Because there isn't a good way to know which spaces are a part of the command, and which delimit arguments. In this case I would use ProcessBuilder.start() rather than Runtime.getRuntime().exec directly. Check out ProcessBuilder and let me know what you think.
I know about ProcessBuilder, but there was an issue with slurping I/O, IIRC.
Looks like the 1.7 release of ProcessBuilder fixes the issue. I'll shift over to using that.
In JBoss Tools ran into this issue in a different context) and stumbled upon your issue. Using MacOS 10.12.4 and java 1.8.0_111 this doesnt seem to be fixed afaics.