Python 2.7 “子流程”;python文件.py“–;如何确保在python3中运行?

Python 2.7 “子流程”;python文件.py“–;如何确保在python3中运行?,python-2.7,python-3.x,subprocess,Python 2.7,Python 3.x,Subprocess,我正在运行以下代码: p = subprocess.getoutput("python ./file.py") 如何确保使用的python版本是python3 谢谢 假设您的控制脚本在python 3中运行,因此您只想运行相同版本的python的子进程,然后尝试: import sys p = subprocess.getoutput("'{}' ./file.py < input.txt".format(sys.executable)) 导入系统 p=subprocess.getou

我正在运行以下代码:

p = subprocess.getoutput("python ./file.py")
如何确保使用的python版本是python3


谢谢

假设您的控制脚本在python 3中运行,因此您只想运行相同版本的python的子进程,然后尝试:

import sys
p = subprocess.getoutput("'{}' ./file.py < input.txt".format(sys.executable))
导入系统 p=subprocess.getoutput(“{}.”/file.py确保使用python 3.x的明显方法是:

p = subprocess.getoutput("python3 ./file.py < input.txt")
p=subprocess.getoutput(“python3./file.py
您可能希望更改代码,使其同时在两个进程上运行:
p=subprocess.check\u output('python./file.py