This works for me :
def p = 'ps aux'.execute() | 'grep foo'.execute() | ['awk', '{ print $1 }'].execute()
p.waitFor()
println p.text
for an unknown reason, the parameters of awk can’t be send with only one string (i don’t know why! maybe bash is quoting something differently). If you dump with your command the error stream, you’ll see error relative to the compilation of the awk script.
Edit : In fact,
"-string-".execute()
delegate toRuntime.getRuntime().exec(-string-)
- It’s bash job to handle arguments containing spaces with ‘ or “. Runtime.exec or the OS are not aware of the quotes
- Executing
"grep ' foo'".execute()
execute the command grep, with'
as the first parameters, andfoo'
as the second one : it’s not valid. the same for awk