Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python2.7中使用子流程时未获得预期结果_Python_Python 2.7 - Fatal编程技术网

在python2.7中使用子流程时未获得预期结果

在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__

我试图在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):

        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编写的,需要保持不变。