在python2.7中使用子流程时未获得预期结果
我试图在Mac电脑上使用python2.7.16中的子进程,但我当前在运行在python2.7中使用子流程时未获得预期结果,python,python-2.7,Python,Python 2.7,我试图在Mac电脑上使用python2.7.16中的子进程,但我当前在运行self.\u execute时得到了错误的输出,我不知道为什么。我想要得到的输出是(True,'Python 2.7.16\n'),但我得到的是(False,'Python 2.7.16\n')。当我在python3中测试这段代码时,它工作得非常好。我有没有做错什么,或者有没有办法解决这个问题 import os import subprocess class Run_Checks: def __init__
self.\u execute
时得到了错误的输出,我不知道为什么。我想要得到的输出是(True,'Python 2.7.16\n'),但我得到的是(False,'Python 2.7.16\n')。当我在python3中测试这段代码时,它工作得非常好。我有没有做错什么,或者有没有办法解决这个问题
import os
import subprocess
class Run_Checks:
def __init__(self):
print self._execute(['python', '--version'])
def _execute(self, _cmd):
process = subprocess.Popen(_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdoutput, stderroutput = process.communicate()
if stdoutput:
return True, stdoutput
return False, stderroutput
def main():
Run_Checks()
if __name__ == "__main__":
main()
任何帮助都将不胜感激。您是否遵循子流程的适当文档?也许Python3和Python2中使用的主要版本的语法有所不同?为什么要使用Python2?@AMC整个框架都是用Python2编写的,需要保持不变。