4 ms·
How about Groovy? ("ls".execute() | "grep -i old".execute()).waitForProcessOutput(System.out, System.out) It can also be written as "ls".execute().or("grep -
by tkot 5y ago
How about Groovy?
("ls".execute() | "grep -i old".execute()).waitForProcessOutput(System.out, System.out)
It can also be written as
"ls".execute().or("grep -i old".execute()).waitForProcessOutput(System.out, System.out)
It's not exactly the same because it uses a thread and a buffer instead of an OS pipe but I guess it's close enough.
- josephcsible 5y agoI wonder why Groovy decided to map "or" to the shell's "|". Wouldn't it have made more sense to map "or" to the shell's "||" and "pipe" to the shell's "|"?
- tkot 5y agoI think this is just how operator overloading works in Groovy: https://groovy-lang.org/operators.html#Operator-Overloading https://groovy-lang.org/operators.html#Operator-Overloading "Or" is the name of the "|" operator. From the looks of it it's impossible to overload "||" in groovy. By the way the "|" operator and the "or" method both call "pipeTo" directly so a third way to write it would be: "ls".execute().pipeTo("grep -i old".execute()).waitForProcessOutput(System.out, System.out)
- nixpulvis 5y agoWhy should I need to explicitly state that I want to wait for my process output? I'm in a shell, I put a `&` afterwards if I want things in the background. The model is synchronous by default.