2017-07-31 98 views
0

尋找如何在groovy(在jenkins中使用)中使用引號內部運行簡單命令的方法。Groovy使用引號執行命令

我的代碼是:

"grep 'text ' /tmp/test.txt".execute()

我希望到grep文本的所有行(和空間後話)。

但是,結果我總是隻得到grep的「文本」(沒有空格)。實際上由於某種原因,groovy會降低我的報價。

+0

的[常規用含有參數空間執行]可能的複製(https://stackoverflow.com/questions/786160/groovy-execute-with-parameters-containing-spaces) – doelleri

回答

0

嘗試以下操作:

def res = ['grep', 'text ', 'test.txt'].execute(null, new File('/tmp/')).text 
+0

你的例子相當於'grep text test.txt',我需要它是'grep'文本'test.txt' – user2988257

0

Groovy中沒有處理好報價。相反,可以使用陣列形式:

['grep', 'text ', '/tmp/test.txt'].execute().text