{"id":2871,"date":"2011-02-15T00:30:36","date_gmt":"2011-02-14T19:00:36","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=2871"},"modified":"2016-12-19T15:22:42","modified_gmt":"2016-12-19T09:52:42","slug":"using-groovy-execute-bash-scripts","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/using-groovy-execute-bash-scripts\/","title":{"rendered":"Using Groovy execute bash scripts"},"content":{"rendered":"<p>Hi Friends,<\/p>\n<p>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&#8217;t work as it was unable to recognize the internal DOS commands like cp, rm etc.<\/p>\n<p>On linux the following code worked but not on windows:<\/p>\n<p>[bash]<br \/>\n File script = new File(&#8216;&lt;My_Script_Path&gt;&#8217;)<br \/>\n script.getText().execute()<br \/>\n [\/bash]<\/p>\n<p>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 :<\/p>\n<p>[bash]<br \/>\n  &quot;&lt;My_Script_Path&gt;&quot;.execute()<br \/>\n[\/bash]<\/p>\n<p>To see the output of the script on the console, we can use the following command :<\/p>\n<p>[bash]<br \/>\n println &quot;&lt;My_Script_Path&gt;&quot;.execute().text<br \/>\n[\/bash]<\/p>\n<p>Hope this helped!<\/p>\n<p>Cheers!<br \/>\n~~Amit Jain~~<br \/>\namit@intelligrape.com<br \/>\nhttp:\/\/www.tothenew.com\/blog\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t work as it was unable to recognize the internal DOS commands like cp, rm etc. On linux the following code worked but not [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":153},"categories":[7],"tags":[519,520,9,472],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2871"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=2871"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2871\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=2871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=2871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=2871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}