Gradle: task's standardOutput to file and terminal simultaneously

exec, gradle, output

Solution

Expounding on Peter N's comment regarding TeeOutputStream:

task sampleTaskWithOutputToFile(type: Exec) {
    commandLine 'someCommand', 'param1'

    doFirst {
        standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
            new FileOutputStream("someFolder/someFile.out"), System.out);
    }
}

Problem

I want to change `standardOutput` of one build task to file, because it will be parsed later by another task. But also, I would like to have simultaneously output in the terminal to see what's going on in the build. This is how I changed output of the task to the file: ``` task sampleTaskWithOutputToFile(type: Exec) { commandLine 'someCommand', 'param1' doFirst { standardOutput = new FileOutputStream('someFolder/someFile.out') } } ``` As I understand, I can write own `OutputStream` implementation with output to file and standard `System.out` simultaneously but I would like to use existing solution. Also, I can not use unix tools like `tee` for that, because task can be launched from any OS (Mac OS, Some Linux or even Windows...) Thanks!

Original source