Friday, March 16, 2007

Groovy Process Piping: Follow-up

Thanks to some comments from those a bit more savvy on this topic I'm suggesting the following method from charlesanderson:

p=['sh','-c','ls -l | sort'].execute()
println p.text

This is mostly cross-platform (assuming CygWin) and is nicely succinct.

I like this method over using the Groovy Groosh module as suggested by Yuri Schimke if only because it doesn't require an import:

def f = gsh.find('.', '-name', '*.java', '-ls');
f.pipeTo(lines);

As always there are many ways to skin the same cat.

1 comment:

Eric Njogu said...

Thank you Sir!

Your code helped me out on an open source project.
The commit:

http://sourceforge.net/p/mlaw/code/ci/b5281b99a2ba7425f5826113f37d55de7de79884/