Using groovy, how do you pipe multiple shell commands?

前端 未结 4 2260
礼貌的吻别
礼貌的吻别 2020-12-05 11:30

Using Groovy and it\'s java.lang.Process support, how do I pipe multiple shell commands together?

Consider this bash command (and assume your username i

4条回答
  •  悲&欢浪女
    2020-12-05 12:08

    You can do this to just let the shell sort it out:

    // slash string at the end so we don't need to escape ' or $
    def p = ['/bin/bash', '-c', /ps aux | grep ' foo' | awk '{print $1}'/].execute()
    p.waitFor()
    println p.text
    

提交回复
热议问题