2

Looking for a way how to run the simple command in groovy (using in jenkins) with quotes inside.

My code is:

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

I want to grep all lines with text (and space after it).

But as a result I'm always getting grep of "text" only (without the space). Actually groovy for some reason drops my quotes.

user2988257
  • 882
  • 4
  • 25
  • 43
  • Possible duplicate of [groovy execute with parameters containing spaces](https://stackoverflow.com/questions/786160/groovy-execute-with-parameters-containing-spaces) – doelleri Jul 31 '17 at 14:18

2 Answers2

2

Groovy doesn't handle quotes well. Instead you can use the array form:

['grep', 'text ', '/tmp/test.txt'].execute().text
John
  • 880
  • 7
  • 11
0

Try the following:

def res = ['grep', 'text ', 'test.txt'].execute( null, new File( '/tmp/' ) ).text
bdkosher
  • 5,753
  • 2
  • 33
  • 40
Mike W
  • 3,853
  • 2
  • 11
  • 18