如何在Windows下的python脚本中运行maven命令

2024-05-13 18:41:55 发布

您现在位置:Python中文网/ 问答频道 /正文

如何用python编写maven命令?我在网上看到了这个例子,但它在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

更新:以下是我得到的错误:

^{pr2}$

Tags: urloutputreturnversionexampledefstderrstdout