0

I wanted to create a groovy script to run grails clean, grails compile and grails run-app, However, I noticed that I cannot run any of the grails commands. In fact then I tried to run the following script on the Groovy Console:

 def envs = System.getenv().collect{"$it.key=$it.value"}
    //println envs
    println "java -version".execute(envs, new File("c:\\")).err.text
    println "grails -version".execute(envs, new File("c:\\")).text

This itself gives me the following output:

groovy> def envs = System.getenv().collect{"$it.key=$it.value"} 
groovy> //println envs 
groovy> println "java -version".execute(envs, new File("c:\\")).err.text 
groovy> println "grails -version".execute(envs, new File("c:\\")).text 


    java version "1.7.0_06"
    Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
    Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

    Exception thrown

    java.io.IOException: Cannot run program "grails" (in directory "c:\"): CreateProcess error=2, The system cannot find the file specified

        at ConsoleScript26.run(ConsoleScript26:4)

    Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

        ... 1 more

Has anyone faced this problem before?

2 Answers 2

1

On Windows, the grails command is a .bat file, and you can't run .bat files directly using Runtime.exec or ProcessBuilder (which is what "...".execute ultimately delegates to).

Use cmd /c:

println ["cmd", "/c", "grails -version"].execute(envs, new File("c:\\")).text

or possibly

println ["cmd", "/c", "grails", "-version"].execute(envs, new File("c:\\")).text

I'm not sure whether the "grails -version" needs to be one argument or two (it may be that both ways work, I'm not currently in a position to test this).

Sign up to request clarification or add additional context in comments.

Comments

0

If java - version runs and grails -version not, it means that you don't updated your PATH environment variable. Append the location to the bin folder to the variable.

Since Grails is just a zip, you need to do it manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.