作为后续行动,我刚才的问题,这得到了迅速解决,我运行下面的Python代码中WinPython:Python函数subprocess.check_output返回CalledProcessError:命令返回非零退出状态
import os, subprocess
os.chdir("C:/Users/Mohammad/Google Drive/PhD/Spyder workspace/production-consumption/logtool-examples/")
logtoolDir="C:/Users/Mohammad/Google Drive/PhD/Spyder workspace/production-consumption/logtool-examples/ "
#processEnv = {'JAVA_HOME': 'C:/Program Files/Java/jdk1.8.0_66/'}
args = r'"org.powertac.logtool.example.ProductionConsumption D:/PowerTAC/Logs/2015/log/powertac-sim-1.state testrunoutput.data"'
subprocess.check_output(['mvn', 'exec:exec', '-Dexec.args=' + args],
shell = True, cwd = logtoolDir)
并出现以下错误:
CalledProcessError: Command '['mvn', 'exec:exec', '-Dexec.args="org.powertac.logtool.example.ProductionConsumption D:/PowerTAC/Logs/2015/log/powertac-sim-1.state testrunoutput.data"']' returned non-zero exit status 1
Apache Maven可执行文件似乎无法运行。我的猜测是,参数被错误地传递给程序。我在参数或logtoolDir参数中找不到任何拼写错误,但也许我错过了某些内容?有任何想法吗?
更新: mvn exec:exec没有运行,因为check_output
已经无法访问Windows的环境变量。我添加了路径变量为processEnv
,现在'mvn','--version'
中的check_output
参数确认Maven运行。代码仍然无法运行,但我想这可能是我如何定义目录的问题。
干杯。
IIRC,如果使用'shell = True',通常将参数作为单个字符串传递。 – mgilson
(另外,由于任何原因,请勿使用'shell = True'。) – geoffspear
@Wooble--该声明可能是_bit_强:-)。有时候很方便。但是,任何使用它的代码都应清楚地记录输入需要100%可信。 – mgilson