with subprocess.Popen(
            cmd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            shell=True,
            text=True
        ) as p:
            p.wait()

            if p.returncode != 0:
                err = p.stderr.read().strip()
                raise Exception(f"failed:\n{cmd}\n{err}")