# commandLine in Exec doesn't get executed right away

**URL:** <https://discuss.gradle.org/t/commandline-in-exec-doesnt-get-executed-right-away/4119>\
**Category:** Old Forum Archive\
**Created:** [September 29, 2014, 11:59pm UTC](https://discuss.gradle.org/t/commandline-in-exec-doesnt-get-executed-right-away/4119 "2014-09-29T23:59:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Kwok](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Stephen\_Kwok](https://discuss.gradle.org/u/Stephen_Kwok)\
**Post date:** [September 29, 2014, 11:59pm UTC](https://discuss.gradle.org/t/commandline-in-exec-doesnt-get-executed-right-away/4119/1 "2014-09-29T23:59:00Z")

</div>

Hi,

I have the following tasks defined. Although the tasks are executed in the order of dependency, I notice that the actual execution of the commands didn’t get executed until println statements of the subsequent tasks got printed. In this case, the brew install didn’t happen until removeOldAssets. Would you please tell me why and how I can fix it? Thank you.

```gradle
task removeR2M(type:Exec){
    ignoreExitValue true
    commandLine 'brew','remove','r2m'
    println "Removing r2m (if exists)"
}
  task installR2M(type:Exec){
    commandLine 'brew','install','https://raw.githubusercontent.com/magnetsystems/r2m-cli/master/brew/r2m.rb'
    println "Installing r2m"
}
installR2M.dependsOn removeR2M
  task removeOldAssets(type: Delete) {
    delete fileTree(dir: workingDir + '/app/src/androidTest/java/com/magneteng/r2m/assets')
    println "Removing old assets"
}
removeOldAssets.dependsOn installR2M

```

Platform: Mac 10.9.5 Gradle: 1.11

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [September 30, 2014, 1:04am UTC](https://discuss.gradle.org/t/commandline-in-exec-doesnt-get-executed-right-away/4119/2 "2014-09-30T01:04:00Z")

</div>

To make the printlns part of task execution (rather than task configuration), you need to wrap them with ‘doLast { … }’. For more information, see “56.1. Build phases” in the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html).
