2016-01-13 31 views
2

當命令更新文本時,某些Gradle Exec任務會產生過多的輸出。抑制Gradle可執行任務中的交互輸出

從終端運行時,這些命令會產生幾行輸出,這些輸出會在適當位置進行更新。

當從內搖籃運行,它們會產生新的輸出線每次的東西被更新,如:

搬運工建立

task dockerBuild(type: Exec) { 
    commandLine 'docker', 'build', '-t', 'foo', '.' 
} 

在運行時會產生:

Sending build context to Docker daemon 557.1 kB 
Sending build context to Docker daemon 1.114 MB 
Sending build context to Docker daemon 1.646 MB 
Sending build context to Docker daemon 2.17 MB 
Sending build context to Docker daemon 2.72 MB 
Sending build context to Docker daemon 3.277 MB 
Sending build context to Docker daemon 3.834 MB 
Sending build context to Docker daemon 4.391 MB 
... hundreds more lines ... 

wget

task fetchData(type: Exec) { 
    commandLine 'wget', 'http://example.org/some/large/file' 
} 

運行時輸出:

HTTP request sent, awaiting response... 200 OK 
Length: 209715200 (200M) [application/zip] 
Saving to: '200MB.zip' 

    0K .......... .......... .......... .......... .......... 0% 5.02M 40s 
50K .......... .......... .......... .......... .......... 0% 6.34M 36s 
100K .......... .......... .......... .......... .......... 0% 6.68M 34s 
150K .......... .......... .......... .......... .......... 0% 6.42M 33s 
200K .......... .......... .......... .......... .......... 0% 6.41M 33s 
250K .......... .......... .......... .......... .......... 0% 7.12M 32s 
... thousands more lines ... 

這是什麼我可以從內部搖籃修復(如請求它以非交互模式執行命令),還是由個別應用程序提供禁用此類輸出的標誌?

回答

1

Exec DSL documentation開始,您可以將可執行文件的輸出重定向到您自己的流。

//store the output instead of printing to the console: 
standardOutput = new ByteArrayOutputStream() 

你可以選擇性地也重定向錯誤流,以保持它完全安靜,但離開它的完整,你會看到在日誌的gradle出任何錯誤。