Background
Groovy is a dynamic java language that runs on JVM. If you are familiar with Java that you will find it very easy to understand and code in Groovy. Will not go into much details now. You can refer to my earlier posts -
To the code....
Put the following code in a file name GroovyTest.groovy and run it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class GroovyTest { public static void main(def args){ println( "Output : " + executeCurlCommand(url)); } def static executeCurlCommand(URL){ def url = "curl " + URL; def proc = url.execute(); def outputStream = new StringBuffer(); proc.waitForProcessOutput(outputStream, System.err) return outputStream.toString(); } } |
After running you can see the output same as executing the command on your console. If you need all outputs on standard output you can do
1 | <b>proc.waitForProcessOutput(System.out, System.err);</b> |
You can see the output by executing the same command in console