【问题标题】:How can I have the Maven output (or command line logs) with Python?如何使用 Python 获得 Maven 输出(或命令行日志)?
【发布时间】:2016-12-02 18:45:26
【问题描述】:

短版: 当我们在循环中执行 Popen 时,是否可以逐渐获得日志?

加长版:

我有一个带有命令行的 bat 文件:

mvn clean -Dtest=LoadTest test
pause

我在 python 脚本中添加了这个蝙蝠:

import os
from subprocess import Popen

os.chdir("../../../../tests")
for i in range(0,3):
    Popen(script.bat)

但是,放bat和python不好,我错了? 所以我测试了在我的python脚本中添加maven命令:

import os
from subprocess import Popen

os.chdir("../../../../tests")
for i in range(0,3):
    cmd= "mvn clean -Dtest=LoadTest test"+str(i)
    Popen(cmd, shell=True)

似乎工作。但我希望日志.. 喜欢 CMD

我试过了:

import os
from subprocess import Popen, PIPE, STDOUT

os.chdir("../../../../tests")
for i in range(0,3):
    cmd= "mvn clean -Dtest=LoadTest test"+str(i)
    Popen(cmd, shell=True)
    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
    output = p.stdout.read()
    print (output)

但是,当我的命令结束时它会打印日志,因此我无法进行负载测试。 是否可以像 CMD 一样逐渐拥有日志?

像蝙蝠一样,是否可以打开CMD并设置命令行?这对我很有用。

编辑:我也尝试添加日志文件

cmd= "clean -Dtest=LoadTest test"+str(i) > LogTest.txt"

使用我的代码,它会阻止执行。我可以并行吗?

感谢您的帮助!

【问题讨论】:

    标签: python cmd


    【解决方案1】:

    我想的更简单:

    cmd= "clean -Dtest=LoadTest test"+str(i) > LogTest"+str(i)+".txt"
    

    我在文件中添加了所有构建结果。它像 CMD 一样跟踪所有内容。

    谢谢

    【讨论】:

      猜你喜欢
      • 2019-10-26
      • 2022-06-15
      • 2013-08-24
      • 2018-10-21
      • 2016-11-14
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 2023-03-31
      相关资源
      最近更新 更多