Skip to content

Instantly share code, notes, and snippets.

@lyuboraykov
Created August 8, 2014 11:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lyuboraykov/8deae849e4812669793a to your computer and use it in GitHub Desktop.
Save lyuboraykov/8deae849e4812669793a to your computer and use it in GitHub Desktop.
Execute shell command with piping in groovy
def command = 'ls | grep foo'
def output = ['bash', '-c', command].execute().in.text
@s5unty
Copy link

s5unty commented Jun 28, 2018

def command = '''
ls | grep foo
ls | grep bar
'''
def proc = ['bash', '-c', command].execute()
proc.waitForOrKill(5000)
def output = proc.in.text

Copy link

ghost commented Feb 24, 2022

How to call groovy variable inside shell?

def var="test"
def command = '''
ls -l
echo $var
'''
def proc = ['bash', '-c', command].execute()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment