2017-07-31 120 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