0

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

我正在运行命令

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

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

4

1 回答 1

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()
于 2013-10-08T22:14:17.453 回答