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 :
To see the output of the script on the console, we can use the following command :
Hope this helped!