Bash管道输出在常规和终端之间是不同的 [英] Bash pipeline output is diff between in groovy and in terminal
本文介绍了Bash管道输出在常规和终端之间是不同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
存在ex / try.groovy,我试试:
exist "ex/try.groovy", i try:
println "ls -al |grep try".execute(null, new File("/home/roroco/Dropbox/jvs/ro-idea/ex")).text
它没有输出任何东西
但是当我尝试跟随时,它会输出try.groovy
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
我的问题是如何使groovy输出与终端相同
my question is how to make groovy output is same with terminal
推荐答案
你由于它由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
这篇关于Bash管道输出在常规和终端之间是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文