# How do I grab the output of a task (going to stdout) and write it to a file?

**URL:** <https://discuss.gradle.org/t/how-do-i-grab-the-output-of-a-task-going-to-stdout-and-write-it-to-a-file/3441>\
**Category:** Old Forum Archive\
**Created:** [November 10, 2012, 9:13pm UTC](https://discuss.gradle.org/t/how-do-i-grab-the-output-of-a-task-going-to-stdout-and-write-it-to-a-file/3441 "2012-11-10T21:13:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Larson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ryan_larson/32/129_2.png) [@Ryan\_Larson](https://discuss.gradle.org/u/Ryan_Larson)\
**Post date:** [November 10, 2012, 9:13pm UTC](https://discuss.gradle.org/t/how-do-i-grab-the-output-of-a-task-going-to-stdout-and-write-it-to-a-file/3441/1 "2012-11-10T21:13:00Z")

</div>

This seems like it should be pretty simple, but I cant find a way to do it.

I have the following task:

```gradle
task dotDescription(type: JavaExec, dependsOn: "classes"){
    classpath configurations.runtime, sourceSets.main.output
    main = "mini.DotTest"
    args relativePath("src\main\java\funs.mini")
}

```

which generates a GraphViz file and outputs it to stdout.

I can run:

```gradle
gradle dotDescription > file.dot

```

but it would be nice if the build would just put it into file.dot for me.

Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![Szczepan\_Faber](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szczepan_faber/32/213_2.png) [@Szczepan\_Faber](https://discuss.gradle.org/u/Szczepan_Faber)\
**Post date:** [November 12, 2012, 11:29am UTC](https://discuss.gradle.org/t/how-do-i-grab-the-output-of-a-task-going-to-stdout-and-write-it-to-a-file/3441/2 "2012-11-12T11:29:00Z")

</div>

In your javaExec task, you can do something like:

```gradle
standardOutput = new ByteArrayOutputStream()
doLast {
  def theOutput = standardOutput.toString()
  //do something with the output, e.g. print to the file, etc.
}

```

Hope that helps!
