-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:這是我得到如下錯誤:
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
以何種方式是不工作?什麼都沒有發生?你有任何錯誤? – Jokab
WindowsError:[錯誤2]系統找不到在「-DgroupId」+ groupId指定的文件; &p = Popen(command,stdout = PIPE,stderr = PIPE)@Jokab – Arshad
很顯然,Windows找不到「mvn.exe」。使用完全限定的路徑,或將其目錄添加到'PATH'。你可以通過'os.environ ['PATH'] + =';%s'%mvn_directory'在腳本中暫時設置後者。 – eryksun