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!
The first "doFirst" function is defined in the initialize task. The second is defined outside of the configuration block. Why doesn't the first instance execute before the second one? The order of execution looks backward. I would have expected the first one, inside the configuration definition, to execute first.
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With