# How to exec a task with args

**URL:** <https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443>\
**Category:** Old Forum Archive\
**Created:** [February 18, 2012, 12:08pm UTC](https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443 "2012-02-18T12:08:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![v\_richomme](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@v\_richomme](https://discuss.gradle.org/u/v_richomme)\
**Post date:** [February 18, 2012, 12:08pm UTC](https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443/1 "2012-02-18T12:08:00Z")

</div>

How can I write a simple exec task ? Example in documentation are too simple. I would like to be able to start mongodb on windows manually so I wrote this :

task startMongoDB(type:Exec) {

workingDir = ‘C:/Developer/mongodb-win32-x86\_64-2.0.2/bin’

commandLine ‘mongod.exe’, ‘–dbpath’, ‘data/db’

}

but it doesnt’ work.

Is it the right syntax or should I use ‘cmd’ ?

---

<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:** [February 18, 2012, 8:13pm UTC](https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443/2 "2012-02-18T20:13:00Z")

</div>

Can you be more specific? What happens, and what’s the command line output? Does -s or -i provide more insight?

PS: Please enclose code snippets in ‘code’ tags.

---

<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:** [February 18, 2012, 8:17pm UTC](https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443/3 "2012-02-18T20:17:00Z")

</div>

Actually I’d expect an error because you are assigning a String to a File property. Simplest solution is to remove the ‘=’ after ‘workingDir’. Such things are documented in the [DSL reference](http://gradle.org/docs/current/dsl/org.gradle.api.tasks.Exec.html).

---

<div class="post-metadata">

**Author:** ![v\_richomme](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@v\_richomme](https://discuss.gradle.org/u/v_richomme)\
**Post date:** [February 19, 2012, 9:29am UTC](https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443/4 "2012-02-19T09:29:00Z")

</div>

Actually it almost works now when I use the following lines :

task startMongoDB(type:Exec) {

commandLine ‘cmd’, ‘/c’, ‘C:/Developer/mongodb-win32-x86\_64-2.0.2/bin/mongod.exe’, ‘–dbpath’, ‘data/db’

}

But the problem is once I have started startMongoDB, mongod is launched and take control of the console so after I cannot start another command to start jetty for instance How can I start it as a separate process ?

---

<div class="post-metadata">

**Author:** ![v\_richomme](https://avatars.discourse-cdn.com/v4/letter/v/c4cdca/32.png) [@v\_richomme](https://discuss.gradle.org/u/v_richomme)\
**Post date:** [February 19, 2012, 7:30pm UTC](https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443/5 "2012-02-19T19:30:00Z")

</div>

Ok I found

---

<div class="post-metadata">

**Author:** ![Helgi\_Sigurdsson](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@Helgi\_Sigurdsson](https://discuss.gradle.org/u/Helgi_Sigurdsson)\
**Post date:** [June 18, 2012, 3:51pm UTC](https://discuss.gradle.org/t/how-to-exec-a-task-with-args/6443/6 "2012-06-18T15:51:00Z")

</div>

what is the solution?
