def check_output(*args, **kwargs):
    """Run command with arguments and return its output as a byte string.

If the return code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and any output in the output attribute."""
    if "stdout" in kwargs:
        raise ValueError("stdout argument not allowed, it will be overriden.")
    p = Popen(stdout=PIPE, *args, **kwargs)
    out, _ = p.communicate()
    rc = p.poll()
    if rc != 0:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = args[0]
        raise CalledProcessError(rc, cmd, output=out)
    return out
Run command with arguments and return its output as a byte string.

If the return code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and any output in the output attribute.
lib/mlpatches/modules/subprocess.py