Reputation: 315
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?
Upvotes: 0
Views: 1252
Reputation: 122414
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).
Upvotes: 1
Reputation:
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.
Upvotes: 0