Using Groovy execute bash scripts

15 / Feb / 2011 by Amit Jain 1 comments

Hi Friends,

Recently I had to execute bash script using groovy on a windows server. Though I could easily make the similar script run on linux, but on windows it just didn’t work as it was unable to recognize the internal DOS commands like cp, rm etc.

On linux the following code worked but not on windows:

File script = new File(‘<My_Script_Path>’)

So after trying few options, I found that we can call execute method on script path also apart from calling it directly on commands and which worked for both windows and linux, as given below :


To see the output of the script on the console, we can use the following command :

println "<My_Script_Path>".execute().text

Hope this helped!

~~Amit Jain~~


comments (1 “Using Groovy execute bash scripts”)

Leave a Reply

Your email address will not be published. Required fields are marked *