Calling command line commands in loop

(Margots Kapacs) #1

Hi, I would like to make the following task: task importNodes(type:Exec){

doFirst{println “importing Nodes…”}

executable “sh”

args “-c”, “drush dei-im nodes --file=20130713_202804_nodes_seo_reference.dataset; drush dei-im nodes --file=20130713_202804_nodes_rental_price.dataset;”


into a loop where the command ‘drush dei-im’ is called fro each dataset file in particular folder. Currently, i have just hard coded two commands with different dataset files but what would be some elegant ways to loop this in groovy/gradle? Thank You.

(Margots Kapacs) #2

this is solution that seems to work

task importNodes() << {
       def dir = new File("sites/default/files/data_export_import/nodes").list().toList()
       for (fileName in dir ) {
              println "ipmorting file ${fileName}..."
                    exec {
                        executable "sh"
                        args "-c", "drush dei-im nodes --file=${fileName}"