FZF
FZF

Reputation: 915

Having trouble with unzipping a file in Groovy

I am trying to unzip/extract file from a compressed file in Groovy. I am using shell command for unzipping (I tried a couple of examples of unzipping using java.util.zip lib I found online, but none worked.) Here is the code using a shell command:

            def soutz = new StringBuilder(), serrz = new StringBuilder()
            def procz = "unzip -o consall.zip consolidated.xml".execute()
            procz.consumeProcessOutput(soutz, serrz)
            procz.waitFor()
            sdc.log.info( "out> $soutz err> $serrz")

This is the output:

out> Archive: /resources/ofac_sdn/temp/consall.zip  
  inflating: consolidated.xml        
 err> 

But the extracted file consolidated.xml doesn't actually materialize (neither while the process is running nor later.) Also, waitFor() or waitForOrKill(5000) doesn't seem to work or make make any difference. Appreciate any suggestions

Upvotes: 0

Views: 476

Answers (1)

daggett
daggett

Reputation: 28564

use ant builder to unzip

new AntBuilder().unzip(src: "consall.zip", dest: "./"){
    patternset{ 
        include(name: "**/consolidated.xml")
    } 
}

Upvotes: 1

Related Questions