Python 如何从subprocess.popen返回结果,格式如下代码

Python 如何从subprocess.popen返回结果,格式如下代码,python,Python,我在res.decode上得到一个错误,说none类型没有属性decode。有人能建议如何处理运行\u进程功能吗?当你说result时,你是什么意思?是否要查看popen的输出?@toheedNiaz my脚本的可能副本在此行“print('进程输出:%s\n'(res.decode(“utf-8”))”处引发错误,因为您的.communicate没有返回任何内容。如果你只是想读出来,那么我可以帮你。我得到了解决方案谢谢 import sys import os import subproces

我在
res.decode
上得到一个错误,说
none类型没有属性decode
。有人能建议如何处理
运行\u进程
功能吗?

当你说result时,你是什么意思?是否要查看popen的输出?@toheedNiaz my脚本的可能副本在此行“print('进程输出:%s\n'(res.decode(“utf-8”))”处引发错误,因为您的
.communicate
没有返回任何内容。如果你只是想读出来,那么我可以帮你。我得到了解决方案谢谢
import sys
import os
import subprocess
import inspect

def run_process(cmd_args):
    with subprocess.popen(cmd_args) as p:
        return (p.communicate())

res = run_process(cmd_args);

if 'with' in inspect.getsource(run_process):
    print("'with' used in 'run_process' function definition.\n")

if 'popen' in inspect.getsource(run_process):
    print("'popen' used in 'run_process' function definition.\n")
    print('process output : %s\n' % (res.decode("utf-8")))

    f.close()