Groovy – Process#pipeTo und Operator Overloading

Operator Overloading ist eine feine Sache. Groovy erweitert z.B. die Klasse java.lang.Process um die Methode “or(Process right)”. “or” wird in Groovy auf den Operator “|” gemappt. Dadurch kann man die Ausgabe eines Prozesses zu einem anderen “pipen”

test.groovy:

#!/usr/bin/env groovy
def p1 = "ls -al".execute()
def p2 = "grep test".execute()
p1 | p2
p2.waitFor()
println p2.text

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s