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>')
 script.getText().execute()
 

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 :

  "<My_Script_Path>".execute()

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!

Cheers!
~~Amit Jain~~
amit@intelligrape.com

http://www.tothenew.com/blog/

FOUND THIS USEFUL? SHARE IT

comments (1 “Using Groovy execute bash scripts”)

Leave a comment -