cimi3386284gt
cimi3386284gt

Reputation: 311

Bash pipeline output is diff between in groovy and in terminal

exist "ex/try.groovy", i try:

println "ls -al |grep try".execute(null, new File("/home/roroco/Dropbox/jvs/ro-idea/ex")).text

it didn't output anything

but when i try following, it will output "try.groovy"

roroco@roroco ~/Dropbox/jvs/ro-idea/ex $ cd /home/roroco/Dropbox/jvs/ro-idea/ex;ls -al |grep try
-rw-r--r--  1 roroco roroco   95 Nov 17 17:28 try.groovy

my question is how to make groovy output is same with terminal

Upvotes: 0

Views: 185

Answers (1)

cfrick
cfrick

Reputation: 37008

you can not use | here as it is handled by the shell. either use sh -c to execute or pipe yourself. See http://groovy.codehaus.org/Process+Management

def p = ['sh', '-c', 'ls /tmp | grep groovy'].execute()
p.waitFor()
println p.text

or

def p1 = 'ls /tmp'.execute()
def p2 = 'grep groovy'.execute()
p1 | p2
p2.waitFor()
println p2.text

Upvotes: 2

Related Questions