groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dierk König <>
Subject Re: Questions about example of piping process output
Date Wed, 19 Aug 2015 20:42:16 GMT

thanks for reading the book!

I was just about to answer when I recognized that I was about to restate the
text that follows the example:

We’re using the pipeTo method of Process, which is invoked by using the overridden
or (|) operator. Then we wait for the process to finish with a safe time to wait, and
print the result.
The observant reader (yes, that’s all of you!) will have recognized that although
the code is a slick solution, there’s also a pure Groovy solution that’s platform independent

In other words, this solution _is_ platform dependent and cygwin is a bit of a "unusual" platform
to run commands at...

keep groovin'

> Am 19.08.2015 um 21:56 schrieb KARR, DAVID <>:
> While reading REGINA, I saw the following script:
> --------------
> def listFiles = 'ls'.execute()
> def ignoreCase = "tr '[A-Z]' '[a-z]'".execute()
> def reverseSort = 'sort -r'.execute()
> listFiles | ignoreCase | reverseSort
> reverseSort.waitForOrKill(1000)
> if(reverseSort.exitValue()) {
>    print reverseSort.err.text
> } else {
>    print reverseSort.text
> }
> -------------------
> I find this curious.  It doesn't even seem to me that this could work as they intended,
although when I run it on Linux, it does apparently print reasonable output.  On Win7/Cygwin
however, it prints "-rThe system cannot find the file specified.".  Any idea what's going
on here?
> Also, the javadoc for "execute()" says that it starts the process and returns the process
object.  Ignoring for a moment why it completely fails on Cygwin, what exactly is the "pipe"
line actually doing?

View raw message