[英]Groovy script to run grails command
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. 我想创建一个Groovy脚本来运行grails clean,grails编译和grails run-app,但是,我注意到我无法运行任何grails命令。 In fact then I tried to run the following script on the Groovy Console:
实际上,然后我尝试在Groovy控制台上运行以下脚本:
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? 有人遇到过这个问题吗?
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). 在Windows上,
grails
命令是一个.bat
文件,您不能直接使用Runtime.exec
或ProcessBuilder
(这是"...".execute
最终委托给的对象)直接运行.bat
文件。
Use cmd /c
: 使用
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). 我不确定“ grails -version”是否需要是一个或两个参数(可能是两种方法都可行,我目前无法测试)。
If java - version
runs and grails -version
not, it means that you don't updated your PATH
environment variable. 如果
java - version
运行,而grails -version
不运行,则意味着您没有更新PATH
环境变量。 Append the location to the bin
folder to the variable. 将位置添加到
bin
文件夹中的变量中。
Since Grails is just a zip, you need to do it manually. 由于Grails只是一个zip,因此您需要手动进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.