Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:27:08+00:00 2026-06-08T03:27:08+00:00

I have a Groovy script that recurses through a directory looking for .png files,

  • 0

I have a Groovy script that recurses through a directory looking for .png files, and invokes pngquant (a command-line utility) on each of. The output of pngquant should be printed on the terminal. The relevant code is:

def command = "pngquant -f -ext .png"

root.eachFileRecurse(groovy.io.FileType.FILES) {File file ->

    if (file.name.endsWith('.png')) { 
        println "Compressing file: $file"

        def imgCommand = "$command $file.absolutePath"

        Process pngquantCmd = imgCommand.execute()
        pngquantCmd.consumeProcessOutput(System.out, System.err)        
    }
}

The script works fine, but once all the files have been processed, it seems that stout is still being redirected, because the command-prompt never appears unless I kill the process with Ctrl + C. Do I need to somehow “undo”

pngquantCmd.consumeProcessOutput(System.out, System.err)        

or is there a better way to redirect the output of this process to the console? I guess I could solve this problem simply by adding System.exit(0), but this doesn’t seem like the right solution. The problem only occurs on Linux.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:27:10+00:00Added an answer on June 8, 2026 at 3:27 am

    Instead of

        pngquantCmd.consumeProcessOutput(System.out, System.err)        
    

    Which will start a couple of threads to read the outputs and plough on regardless of the process’ situation, you should try

        pngquantCmd.waitForProcessOutput(System.out, System.err)
    

    Which will redirect the process output and then wait for it to finish before moving on 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar to this question I have a small groovy test script that basically uses
I have written a very complex database migration script in Groovy, that runs just
I have a groovy script that needs a library in a jar. How do
I have a simple groovy script that generates xml def builder = new groovy.xml.StreamingMarkupBuilder()
Hey I have created a Groovy script that will extract the version numbers of
I have just tried to write my first ever Groovy script and noticed that
I have a groovy/grails application that needs to serve images It works fine on
I have seen the at (@) sign in Groovy files and I don't know
I have one groovy script which print some statistics: println: ... now I have
We have an existing java-based heavyweight project that needed an interactive script interpreter. After

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.