Bhanuchander Udhayakumar
Bhanuchander Udhayakumar

Reputation: 1621

How to execute simply list of shell commands with pipe using Groovy?

Already we know that,

def total_cmd = ("less test.txt").execute() | ("wc -l").execute()
total_cmd.waitFor()
println total_cmd.getText()

How can i do this from a list of n commands like,

def cmd_list = [ "cmd1".execute(), "cmd2".execute(),....,"cmdn".execute()]

Upvotes: 0

Views: 354

Answers (1)

ernest_k
ernest_k

Reputation: 45309

You can execute, then reduce:

total_cmd = cmd_list*.execute().inject{a,b -> a | b}

This assumes a|b == b|a

Upvotes: 2

Related Questions