Casey Patton
Casey Patton

Reputation: 4091

Executing unzip command from Groovy

I'm trying to run the unzip shell command from within Groovy.

I'm running the command

"unzip ~/Documents/myFile.txt.zip -d ~/Documents/".execute()

but it's not working. When I copy the exact command into my terminal it works. How can I do this from groovy?

Upvotes: 0

Views: 467

Answers (1)

Dave Newton
Dave Newton

Reputation: 160201

There's no ~ as far as Groovy is concerned; use an actual path.

groovy:000> p = "ls -CF /Users/Dave".execute()
===> java.lang.UNIXProcess@2603826d
groovy:000> p.waitFor()
===> 0
groovy:000> p.in.text
===> Desktop/       Movies/         bin/
Documents/      Music/          node_modules/
Downloads/      Pictures/
Dropbox/        Public/     
Library/        ScreenshotOnFail/

You can always use System.getProperty("user.home"), e.g.,

p = "ls -CF ${System.getProperty('user.home')}".execute()

Upvotes: 1

Related Questions