wention
1/3/2018 - 3:49 AM

cmd_run.py

import subprocess

def cmd_run(cmd):
    if isinstance(cmd, str):
        cmd = cmd.split()
    if not isinstance(cmd, list):
        raise Exception("TypeError cmd_run only accept str,list")
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()

    return out, err, p.returncode