从Groovy执行解压缩命令

时间:2013-10-08 22:07:08

标签: shell groovy

我正在尝试从Groovy中运行unzip shell命令。

我正在运行命令

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

但它不起作用。当我将确切的命令复制到我的终端时,它可以工作。我如何从groovy做到这一点?

1 个答案:

答案 0 :(得分:1)

就Groovy而言,没有~;使用实际路径。

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/

您可以随时使用System.getProperty("user.home"),例如

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