1

Suppose I have a block of Gant code:

 target(echo:"test"){
    ant.echo(message:"hi")
 }
 setDefaultTarget("echo")

This is usually run from a command line.

How could I place the block in a Grails controller and run it from there?

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
john
  • 2,572
  • 11
  • 35
  • 51

2 Answers2

0

You can create a groovy script say DynaScript_.groovy that contains your Gant code and place this script file in the {grailsHome}/scripts folder.

And then you can invoke the script file from your controller like this:

class FooController {

     def index = {
           def process  =  "cmd /c grails dyna-script".execute()
           def out = new StringBuilder()
       process.waitForProcessOutput(out, new StringBuilder())
           println "$out" 
     }
}

It's important that your script name ends with an underscore.

0

You can use AntBuilder for this:

class FooController {

   def index = {
      def ant = new AntBuilder()
      ant.echo(message:"hi")
   }
}
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • Dear Burt, thank you for your nice solution. Does this mean that I cannot simply copy the rich grails scipts to my controllers for use? – john Sep 21 '10 at 17:18