在Gradle exec任务中禁止交互输出 [英] Suppressing interactive output in Gradle exec tasks

查看:64
本文介绍了在Gradle exec任务中禁止交互输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当命令在适当位置更新文本时,某些Gradle Exec任务会产生过多的输出.

Some Gradle Exec tasks produce excessive output when the command updates text in place.

从终端运行时,这些命令会产生几行输出,并在适当位置进行更新.

When run from a terminal, these commands produce a couple of lines of output that are updated in place.

在Gradle中运行时,每次更新时它们都会产生新的输出行,例如:

When run from within Gradle, they produce a new line of output each time something is updated, e.g.:

docker build :

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 ...

我可以在Gradle中解决此问题吗(例如,要求它以非交互模式执行命令),还是由单个应用程序提供禁用此类输出的标志?

Is this anything I can fix from within Gradle (e.g. ask it to execute commands in non-interactive mode), or is it down to individual applications to provide flags for disabling this sort of output?

推荐答案

来自 Exec DSL文档,您可以将可执行文件的输出重定向到您自己的流.

From Exec DSL documentation, you can redirect the output of the executable to your own stream.

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

您还可以选择重定向错误流以使其完全安静,但是通过使其保持完整,您将在gradle日志中看到任何退出错误.

You could optionally also redirect error stream to keep it completely quiet, but by leaving it intact, you'll see any exit errors in gradle log.

这篇关于在Gradle exec任务中禁止交互输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆