groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dierk König <dierk.koe...@canoo.com>
Subject Re: Questions about example of piping process output
Date Wed, 19 Aug 2015 21:16:43 GMT
the processes are started but they are "lazy" and concurrent.

Isn't that nice? 

Working in a (unix) shell is like working in a functional language...

cheers
Dierk 

> Am 19.08.2015 um 23:02 schrieb KARR, DAVID <dk068x@att.com>:
> 
>> -----Original Message-----
>> From: Dierk König [mailto:dierk.koenig@canoo.com]
>> Sent: Wednesday, August 19, 2015 1:42 PM
>> To: users@groovy.incubator.apache.org
>> Subject: Re: Questions about example of piping process output
>> 
>> Hi,
>> 
>> 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...
> 
> What I'm confused about is that running "execute()" seems to say that it starts the process,
but those three seem to be started independently, and then we later attempt to connect them
with a pipe.  Does "execute()" not actually start the process?  The second two processes need
input that isn't provided yet.
> 
>>> Am 19.08.2015 um 21:56 schrieb KARR, DAVID <dk068x@att.com>:
>>> 
>>> 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?
> 


Mime
View raw message