# Exec task and killing processes?

**URL:** <https://discuss.gradle.org/t/exec-task-and-killing-processes/6189>\
**Category:** Old Forum Archive\
**Created:** [September 12, 2013, 7:05pm UTC](https://discuss.gradle.org/t/exec-task-and-killing-processes/6189 "2013-09-12T19:05:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcel\_Overdijk](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/marcel_overdijk/32/144_2.png) [@Marcel\_Overdijk](https://discuss.gradle.org/u/Marcel_Overdijk)\
**Post date:** [September 12, 2013, 7:05pm UTC](https://discuss.gradle.org/t/exec-task-and-killing-processes/6189/1 "2013-09-12T19:05:00Z")

</div>

I’m looking at integrating Grunt with Gradle by using the exec task.

Basically I’m trying to call this from Gradle: cmd /c grunt --no-color watch

If I run the above command it runs node.exe on my machine. As this Grunt task watches for particular file changes the process will not end. As soon as I hit Ctrl-C the command ends and also the node process is killed automatically.

When I run something similar from Gradle using the exec task:

task grunt(type: Exec) {

commandLine = [“cmd”, “/c”, “grunt”, “–no-color”, “watch”] }

I can run the programm successfully. The Gradle task keeps running as the actual Grunt task is doing that as well.

Now the problem arises when I Ctrl-C the running Gradle task. Gradle stops it task, however the node process keeps running…

Any ideas if there is a way to kill it?

---

<div class="post-metadata">

**Author:** ![Jay\_Berkenbilt](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jay_berkenbilt/32/306_2.png) [@Jay\_Berkenbilt](https://discuss.gradle.org/u/Jay_Berkenbilt)\
**Post date:** [September 19, 2013, 6:21pm UTC](https://discuss.gradle.org/t/exec-task-and-killing-processes/6189/2 "2013-09-19T18:21:00Z")

</div>

I’m running into essentially the same issue. I’m experimenting with using gradle as a wrapper around some other build tools during a migration process, and I’m having gradle actually invoke ant using exec { … }. If I CTRL-C the gradle process, on Windows, the ant process continues to run but with its output going into a black hole. On Linux, where CTRL-C sends SIGINT to the process group, both gradle and the ant process terminate.

---

<div class="post-metadata">

**Author:** ![Jay\_Berkenbilt](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jay_berkenbilt/32/306_2.png) [@Jay\_Berkenbilt](https://discuss.gradle.org/u/Jay_Berkenbilt)\
**Post date:** [September 19, 2013, 6:29pm UTC](https://discuss.gradle.org/t/exec-task-and-killing-processes/6189/3 "2013-09-19T18:29:00Z")

</div>

It’s worth noting that running ant from ant in this particular way exhibits the same behavior.

```gradle
<project>
  <target name="build">
    <exec executable="cmd">
      <arg value="/c"/>
      <arg value="ant"/>
      <arg value="-f"/>
      <arg value="build/build.xml"/>
      <arg value="dev"/>
    </exec>
  </target>
</project>

```

---

<div class="post-metadata">

**Author:** ![covolution](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@covolution](https://discuss.gradle.org/u/covolution)\
**Post date:** [November 26, 2013, 2:47pm UTC](https://discuss.gradle.org/t/exec-task-and-killing-processes/6189/4 "2013-11-26T14:47:00Z")

</div>

Any suggestions on the best way to achieve this?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [November 27, 2013, 5:31pm UTC](https://discuss.gradle.org/t/exec-task-and-killing-processes/6189/5 "2013-11-27T17:31:00Z")

</div>

No way to do this from within Gradle currently. You’ll have to use ProcessBuilder to launch the process and then you can use destroy().
