我正在尝试从Groovy中运行unzip shell命令。
我在运行命令
"unzip ~/Documents/myFile.txt.zip -d ~/Documents/".execute()但这不管用。当我把准确的命令拷贝到我的终端上时,它就能工作了。我怎样才能从groovy中做到这一点呢?
发布于 2013-10-08 22:14:17
就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()https://stackoverflow.com/questions/19259360
复制相似问题