簡體   English   中英

Groovy腳本運行grails命令

[英]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.execProcessBuilder (這是"...".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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM