我正在尝试从Groovy中运行unzip shell命令。
我正在运行命令
"unzip ~/Documents/myFile.txt.zip -d ~/Documents/".execute()
但它不起作用。当我将确切的命令复制到我的终端时,它可以工作。我如何从groovy做到这一点?
答案 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()