# Calling command line commands in loop

**URL:** <https://discuss.gradle.org/t/calling-command-line-commands-in-loop/3631>\
**Category:** Old Forum Archive\
**Created:** [July 13, 2013, 8:53pm UTC](https://discuss.gradle.org/t/calling-command-line-commands-in-loop/3631 "2013-07-13T20:53:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Margots\_Kapacs](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Margots\_Kapacs](https://discuss.gradle.org/u/Margots_Kapacs)\
**Post date:** [July 13, 2013, 8:53pm UTC](https://discuss.gradle.org/t/calling-command-line-commands-in-loop/3631/1 "2013-07-13T20:53:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Margots\_Kapacs](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@Margots\_Kapacs](https://discuss.gradle.org/u/Margots_Kapacs)\
**Post date:** [July 13, 2013, 11:13pm UTC](https://discuss.gradle.org/t/calling-command-line-commands-in-loop/3631/2 "2013-07-13T23:13:00Z")

</div>

this is solution that seems to work

```gradle
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}"
                    }
       }
}

```
