2010-03-11 20 views
9

çalıştırmak için harika içinde() yürütmek kullanmak Genellikle inşa komut satırından bu iki komut (dos) kullanarak projenasıl herhangi bir komut

G:\> cd c: 
C:\> cd c:\my\directory\where\ant\exists 
C:\my\directory\where\ant\exists> ant -Mysystem 
... 
..... 
build successful 

Ne yerine harika yukarıda yapmak istiyorsanız? , "cd c:".execute() olan cd adlı bir program çalıştırmayı dener

Caught: java.io.IOException: Cannot run program "cd": CreateProcess error=2, The 
system cannot find the file specified 
     at ant_groovy.run(ant_groovy.groovy:2) 

cevap

5

bu thread (2 parçası) göre: harika execute() yöntemi vardır ancak aşağıdaki benim için çalışmaz:

def cd_command = "cd c:" 
def proc = cd_command.execute() 
proc.waitFor() 

o hata verir bir program değil, yerleşik bir kabuk komutu. (Test) aşağıdaki gibi

geçici çözüm dizini değiştirmek olacaktır:

System.setProperty("user.dir", "c:")

3
"your command".execute(null, /the/dir/which/you/want/to/run/it/from) 

ne istediğini yapmalıdır.

13

Ya da daha açık bir şekilde, ben binil çözümü

"your command".execute(null, new File("/the/dir/which/you/want/to/run/it/from")) 
4

Teşekkür Noel ve Binil okumak gerektiğini düşünüyorum, ben bir yapı Maven ile benzer bir sorun vardı.

projects = ["alpha", "beta", "gamma"] 

projects.each{ project -> 
    println "*********************************************" 
    println "now compiling project " + project 
    println "cmd /c mvn compile".execute(null, new File(project)).text 
} 
İlgili konular