2016-07-25 3 views
-1

ausführen Wie schreibe ich einen Maven-Befehl in Python? Ich habe dieses Beispiel online gesehen, aber es scheint nicht in Windows zu funktionieren.Wie maven Befehl in einem Python-Skript in Windows

def local2(command, print_command=False): 
    from subprocess import Popen, PIPE 
    p = Popen(command, stdout=PIPE, stderr=PIPE) 
    if print_command: print " ".join(command) 
    output, errput = p.communicate() 
    return p.returncode, output, errput 

def uploadQAJavaToNexus(): 
    url = "example" 
    groupId = "example" 
    artifactId = "example" 
    repositoryId = "example" 
    # filePath = 
    version = "version" 

    status, stdout, stderr = local2([ 
            "mvn", 
            "deploy:deploy-file", 
            "-Durl=" +url, 
            "-DrepositoryId=" +repositoryId, 
            "-Dversion=" + version, 
            "-Dfile=" + "path" 
            "-DartifactId=" + artifactId, 
            "-Dpackaging=" + "jar", 
            "-DgroupId" + groupId, 
            ]) 
    return status, stdout, stderr 

UPDATE: Dies ist der Fehler, den ich unten bin immer:

Traceback (most recent call last): 
    File "C:\PythonProject\src\Get.py", line 355, in <module> 
    uploadQAJavaToNexus() 
    File "C:\Get.py", line 250, in uploadQAJavaToNexus 
    "-DgroupId" + groupId, 
    File "C:\Get.py", line 227, in local2 
    p = Popen(command, stdout=PIPE, stderr=PIPE) 
    File "C:\Python27\lib\subprocess.py", line 710, in __init__ 
    errread, errwrite) 
    File "C:\Python27\lib\subprocess.py", line 958, in _execute_child 
    startupinfo) 
WindowsError: [Error 2] The system cannot find the file specified 
+0

In welcher Weise ist es nicht funktioniert? Passiert nichts? Haben Sie Fehler? – Jokab

+0

WindowsError: [Fehler 2] Das System kann die unter "-DgroupId" angegebene Datei nicht finden + groupId; & p = Popen (Befehl, stdout = PIPE, stderr = PIPE) @Jokab – Arshad

+0

Es ist klar, dass Windows "mvn.exe" nicht finden kann. Verwenden Sie den vollqualifizierten Pfad, oder fügen Sie sein Verzeichnis zu "PATH" hinzu. Sie können letzteres temporär in Ihrem Skript über 'os.environ ['PATH'] + = ';% s'% mvn_directory' einstellen. – eryksun

Antwort

-1

Ich ziehe Stoff verwenden (http://www.fabfile.org/):

from fabric import local  
def maven_start(): 
    local('<cmd>') 


$ fab maven_start 
+0

Ich verstehe nicht, was du meinst. Könnten Sie bitte etwas ausarbeiten? local erhält meinen undefinierten Fehler – Arshad

Verwandte Themen