2010-03-11 7 views
9

चलाने के लिए मैं आम तौर पर निर्माण अपने प्रोजेक्ट कमांड लाइन से इन दो आदेश (डॉस) का उपयोग करकैसे() पर अमल ग्रूवी में उपयोग करने के लिए किसी भी कमांड

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

क्या मैं बजाय ग्रूवी से ऊपर क्या करना चाहते हैं? ग्रूवी execute() विधि है, लेकिन निम्नलिखित मेरे लिए काम नहीं करता है:

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

यह त्रुटि देता है:

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) 

उत्तर

5

इस thread (2 भाग) के अनुसार, "cd c:".execute()cd नाम के एक कार्यक्रम है जो चलाने की कोशिश करता है एक कार्यक्रम नहीं बल्कि एक अंतर्निहित खोल कमांड।

वैकल्पिक हल निर्देशिका बदलने के लिए होगा नीचे के रूप में (परीक्षण नहीं):

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

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

जैसे आप चाहते हैं क्या करना चाहिए।

13

या अधिक स्पष्ट रूप से, मुझे लगता है कि binil के समाधान पढ़ना चाहिए

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

धन्यवाद नोएल और Binil, मैं एक निर्माण Maven के साथ एक समान समस्या थी।

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

projects.each{ project -> 
    println "*********************************************" 
    println "now compiling project " + project 
    println "cmd /c mvn compile".execute(null, new File(project)).text 
} 
संबंधित मुद्दे