Question

I have written my own gant script which works fine from the command line. Now I need to run this script from a grails project like this:

def outputMessage

try{

    GroovyScriptEngine engine = new GroovyScriptEngine("/www", this.getClass().getClassLoader());
    engine.run("scripts/MyOwnScript_.groovy", "param1 param2")
    outputMessage = "<br> OK: Script run successfully"
}
catch (Exception e) {
    outputMessage += "<br> ERROR: There has been running the script"
}

The error I am getting is "No such property: includeTargets for class: MyOwnScript_", as my gant script requires some other scripts.

Does anybody know a proper way to get it working?

Was it helpful?

Solution 2

Answering my own question. The main problem was that I need to run the grails using the full path like this:

Map<String, String> env = System.getenv()
final processBuilder = new ProcessBuilder()
processBuilder.directory(new File("folderFromWhereIWantToRunTheGantScript"))
processBuilder.command([env['GRAILS_HOME']+"/bin/grails","MyOwnScript param1 param2"])
println processBuilder.directory()
Process proc = processBuilder.start()
proc.consumeProcessOutput(out, err)

proc.waitFor()

OTHER TIPS

Have you tried to get path to your script folder and execute an external process like

["groovy", "scripts/MyOwnScript_.groovy", "param1", "param2"].execute()

See here for more info about running external process in groovy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top