使用 subprocess.Popen Python 执行两个命令

Execute two commands with subprocess.Popen Python

我想通过从 python 脚本中调用来执行一个批处理文件。关键是这个批次需要设置JAVA_HOME。我不想在系统环境变量中设置这个变量,我想从 python 开始。有没有通过 Like this

执行两个批处理命令
p = Popen("""set JAVA_HOME=D:\GIT\G_ATC_FCT_SW_HSM_Daimler\Tools\jdk-8.0.242.08-hotspot;D:\GIT\G_ATC_FCT_SW_HSM_Daimler\Tools\plugins\com.nxp.id.jcop.eclipse_6.0.0.8\cmds\converter.bat Java_Card_Converter-3.0.5""")
    stdout, stderr = p.communicate()

但是我遇到了这个错误 FileNotFoundError: [WinError 2] The specified file could not be found。 是否可以从 popen 做到这一点?

@GPhilo 提供的回复帮助了我。这是我的问题的解决方案:

Then since you don't actually need to run two commands, but only run the script with a modified environment, use the solution from here: Python subprocess/Popen with a modified environment – GPhilo