2016-07-25 11 views
-1

pythonでmavenコマンドを書くにはどうすればいいですか?私はこの例をオンラインで見ましたが、Windowsでは動作していないようです。Windowsのpythonスクリプトでmavenコマンドを実行する方法

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:私は生地(http://www.fabfile.org/)を使用することを好む

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

をそれが動作しませんか?何も起こらない?何かエラーがありますか? – Jokab

+0

WindowsError:[エラー2] "-DgroupId" + groupIdで指定されたファイルが見つかりません。 &p = Popen(command、stdout = PIPE、stderr = PIPE)@Jokab – Arshad

+0

Windowsは "mvn.exe"を見つけることができません。完全修飾パスを使用するか、そのディレクトリを 'PATH'に追加してください。後者を 'os.environ ['PATH'] + = ';%s'%mvn_directory'を介してスクリプトで一時的に設定することができます。 – eryksun

答えて

-1

:これは私が下記取得していますエラーですどのように

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


$ fab maven_start 
+0

あなたは何を意味するのか分かりません。あなたは詳細を教えていただけますか?ローカルは私の未定義のエラーが与えられます – Arshad

関連する問題