[英]Groovy script to run grails command
我想创建一个Groovy脚本来运行grails clean,grails编译和grails run-app,但是,我注意到我无法运行任何grails命令。 实际上,然后我尝试在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
这本身给了我以下输出:
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
有人遇到过这个问题吗?
在Windows上, grails
命令是一个.bat
文件,您不能直接使用Runtime.exec
或ProcessBuilder
(这是"...".execute
最终委托给的对象)直接运行.bat
文件。
使用cmd /c
:
println ["cmd", "/c", "grails -version"].execute(envs, new File("c:\\")).text
或可能
println ["cmd", "/c", "grails", "-version"].execute(envs, new File("c:\\")).text
我不确定“ grails -version”是否需要是一个或两个参数(可能是两种方法都可行,我目前无法测试)。
如果java - version
运行,而grails -version
不运行,则意味着您没有更新PATH
环境变量。 将位置添加到bin
文件夹中的变量中。
由于Grails只是一个zip,因此您需要手动进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.