0

In the code provided below I can print each of the file names in the directory, but when it reaches the Exec command it only performs an Exec on the last file.

task frmf2xml(type:Exec)  {
    new File('src/orca/').eachFile {file ->
        if(file.name.endsWith(".fmb")){
            println file
            commandLine 'cmd', '/c', 'frmf2xml.bat', file, 'OVERWRITE=YES'
        }
   }
}

I would like it to run the tool on every file

rnrneverdies
  • 15,243
  • 9
  • 65
  • 95
  • You copied the exact problem and code from this link, why? http://forums.gradle.org/gradle/topics/iterative_exec – chrki Dec 25 '14 at 11:05
  • @chrki LOL yes looking a solution of course. btw, you linked this code on [your great answer](http://stackoverflow.com/a/27639730/2573335) – rnrneverdies Dec 25 '14 at 14:13
  • @chrki i needed to know if it could solve, and *gave you the bounty*, btw: the solution provided in the link, doesn't work. – rnrneverdies Dec 25 '14 at 14:19

1 Answers1

0

Actually i found a Solution, using execute().

task frmf2xml()  {
    new File('src/orca/').eachFile {file ->
        if(file.name.endsWith(".fmb")){                
            def cmd = "cmd /c frmf2xml.bat ${file} OVERWRITE=YES"
            def result = cmd.execute();
            result.waitFor();
        }
   }
}
billjamesdev
  • 14,554
  • 6
  • 53
  • 76
rnrneverdies
  • 15,243
  • 9
  • 65
  • 95
  • 1
    At the very least, you'll have to wrap the whole task body with `doLast:`: `task frmf2xml { doLast { ... } }`. Otherwise the commands will get executed on every Gradle invocation (no matter which task is invoked) and before any task has run (configuration vs. execution phase). Instead of Groovy's `String#execute`, it's more idiomatic to use Gradle's `project.exec { ... }`. – Peter Niederwieser Dec 26 '14 at 12:59