0
我試圖從Groovy內運行unzip shell命令。從Groovy執行unzip命令
我運行命令
"unzip ~/Documents/myFile.txt.zip -d ~/Documents/".execute()
,但它不工作。當我將確切的命令複製到我的終端時,它可以工作。我怎麼能從groovy做到這一點?
我試圖從Groovy內運行unzip shell命令。從Groovy執行unzip命令
我運行命令
"unzip ~/Documents/myFile.txt.zip -d ~/Documents/".execute()
,但它不工作。當我將確切的命令複製到我的終端時,它可以工作。我怎麼能從groovy做到這一點?
就Groovy而言,沒有~
;使用實際路徑。
groovy:000> p = "ls -CF /Users/Dave".execute()
===> [email protected]
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()
,我一直在敲打我的頭靠在了一段簡單的解決方案。謝謝! –
@CaseyPatton請注意,'p.err.text'會顯示關於未知目錄的錯誤消息。 –