且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Bash管道输出在常规和终端之间是不同的

更新时间:2022-11-30 15:56:07

你由于它由shell处理,因此在此处不能使用 | 。或者使用 sh -c 来执行或管理自己。请参阅 http://groovy.codehaus.org/Process+Management

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

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