calling a groovy script from another groovy script.

View: New views
3 Messages — Rating Filter:   Alert me  

calling a groovy script from another groovy script.

by Mauro Zallocco-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am in the process of converting a number of dos batch files into groovy scripts.
My approach is to create a groovy equivalent for each dos batch file which executes with the same functionality.
Now the dos batch files call other batch files sometimes in other directories.

So I have something like the following:
file1.bat
echo "hello world"
pushd ..\..\build
call file2.bat
popd
echo "done"

file1.groovy
println "hello world"
?????
println "done"

Any suggestions would be appreciated.


Re: calling a groovy script from another groovy script.

by HamletDRC :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can load and execute a Groovy File by doing something like this:

http://groovy.codehaus.org/api/groovy/lang/GroovyClassLoader.html

Class c = new GroovyClassLoader().parseClass(new File(...))
((Script)c).run()

--
Hamlet D'Arcy
hamletdrc@...




On Mon, Oct 26, 2009 at 10:15 PM, Mauro Zallocco <mzallocco@...> wrote:

> I am in the process of converting a number of dos batch files into groovy
> scripts.
> My approach is to create a groovy equivalent for each dos batch file which
> executes with the same functionality.
> Now the dos batch files call other batch files sometimes in other
> directories.
>
> So I have something like the following:
> file1.bat
> echo "hello world"
> pushd ..\..\build
> call file2.bat
> popd
> echo "done"
>
> file1.groovy
> println "hello world"
> ?????
> println "done"
>
> Any suggestions would be appreciated.
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


--
Hamlet D'Arcy

Re: calling a groovy script from another groovy script.

by Roshan Dawrani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Or you can also do it like:

================Script1.groovy================
....some Script1 code....

this.evaluate(new File('....Script2.groovy'))

....some more Script1 code....
===========================================

-- Roshan

On Tue, Oct 27, 2009 at 5:15 PM, Hamlet D'Arcy <hamletdrc@...> wrote:
You can load and execute a Groovy File by doing something like this:

http://groovy.codehaus.org/api/groovy/lang/GroovyClassLoader.html

Class c = new GroovyClassLoader().parseClass(new File(...))
((Script)c).run()

--
Hamlet D'Arcy
hamletdrc@...




On Mon, Oct 26, 2009 at 10:15 PM, Mauro Zallocco <mzallocco@...> wrote:
> I am in the process of converting a number of dos batch files into groovy
> scripts.
> My approach is to create a groovy equivalent for each dos batch file which
> executes with the same functionality.
> Now the dos batch files call other batch files sometimes in other
> directories.
>
> So I have something like the following:
> file1.bat
> echo "hello world"
> pushd ..\..\build
> call file2.bat
> popd
> echo "done"
>
> file1.groovy
> println "hello world"
> ?????
> println "done"
>
> Any suggestions would be appreciated.
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email