Suppressing interactive output in Gradle exec tasks

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.

  • Can I configure ECS to automatically purge old container [images] from my EC2 instances?
  • Certificate errors after changing docker location on windows
  • MongoDb docker hangs after some requests
  • Docker: Can't get up networking
  • git runner is unable to access
  • Letting a container know its exposed ports in Docker
  • 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', '.'
    }
    

    when run produces:

    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'
    }
    

    when run outputs:

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

    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?

  • How can I write Dockerfile for Yesod? “RUN yesod init -n myApp -d postgresql” didn't work as expected
  • Docker For Windows - Java app deployed on a container gets a connection refused error when calling another java app deployed on another container
  • Python docker-py Connection Refused
  • Docker for Windows: cannot assign requested address
  • Cannot hit docker container running locally
  • Create docker image with php and mysql
  • One Solution collect form web for “Suppressing interactive output in Gradle exec tasks”

    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()
    

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.