0

I have this command

find path/tools/ \( -name '*.sh' -o -name '*.exe' -o ! -name "*.*" \) -exec chmod +x {} \;

How can I define it in my Gradle exec task?

task xPermTools (type: Exec){
    workingDir '../'
    commandLine "find", "path/tools/", "\( -name *.sh -o -name '*.exe' -o ! -name "*.*" \)", "-exec", "chmod", "+x", "{}", "\;"
}

Do I need to give it as a list? The above piece of code returns an error such as

build file '/home/li_user/path_root/build.gradle': 422: unexpected char: '\' @ line 422, column 44.

Additionally, how do I convert this to a groovy command? I want to set permissions for shell scripts from groovy.

Müller
  • 973
  • 6
  • 19
  • 38
  • http://stackoverflow.com/questions/36482293/set-filemode-for-sh-when-copying-files-to-tar-by-convention – tim_yates Feb 14 '17 at 10:42
  • Are you saying the above gradle command is not working? If so, you might need to use the full path of find, i.e. something like `/usr/bin/find` (or whatever `which find` returns on your system). As for "as a list", you should not need to use a list when setting the command line as the [gradle exec task commandLine method](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html#org.gradle.api.tasks.Exec:commandLine(java.lang.Iterable)) uses varargs. As for converting it to pure groovy, you can do `"some command with args".execute()` in groovy which returns a Process object. – Matias Bjarland Feb 14 '17 at 13:06
  • Thanks but I get a message which says there is an error with the find statement. But when I run the same command in my shell, I don't get any errors. It gets the job done. And `/usr/bin` is already there in $PATH and I have also tried running the full path from the commandLine. I have attached the error message in my question. – Müller Feb 14 '17 at 13:18
  • Don't try to quote or escape things, only your shell needs quoted (e.g. '(' and ';') and put each parameter in it's own string (e.g. "-name", "*.exe" ) – cfrick Feb 15 '17 at 10:18

0 Answers0