如何从subprocess.popen返回结果形成以下代码

时间:2018-04-15 09:47:41

标签: python

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()

我在res.decodenone type has no attribute decode时收到错误消息。有人会建议如何处理run_process函数吗?

0 个答案:

没有答案