使用子进程modu的字符串参数

2024-06-02 08:56:50 发布

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

我使用Python来简化Maven中的一些命令。我有一个在调试模式下调用mvn test的脚本。在

from subprocess import call
commands = []
commands.append("mvn")
commands.append("test")
commands.append("-Dmaven.surefire.debug=\"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE\"")
call(commands)

问题出在-Dmaven.surefire.debug行中,该行接受必须在配额中的参数,我不知道如何正确地执行该操作。当我打印这个列表时它看起来很好,但是当我运行脚本时,我得到Error translating CommandLine并且调试行永远不会执行。在


Tags: fromdebugtestimport命令脚本callcommands
1条回答
网友
1楼 · 发布于 2024-06-02 08:56:50

只有执行命令的shell才需要配额。在

如果您直接从shell执行上述调用,那么您可能会这样做

mvn test -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE"

有了这些"符号,您(简单地说)告诉shell忽略其中的空格。在

用参数调用程序

^{pr2}$

所以

from subprocess import call
commands = []
commands.append("mvn")
commands.append("test")
commands.append("-Dmaven.surefire.debug=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE")
call(commands)

应该是该走的路。在

相关问题 更多 >