def run()

in pantri/scripts/lib/utils.py [0:0]


def run(cmd, cwd=None, sanitize=True):
    """
  Quick clone of shell_tools.run.

  TODO: Improve error handling
  """

    # TODO Determine if there is a better way to do this.
    # Setting cwd within the repo
    if not cwd:
        cwd = os.path.dirname(get_paths()["repo_root"])

    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=cwd, universal_newlines=True)
    stdout, stderr = p.communicate()
    status_code = p.wait()

    result_dict = {
        "stdout": sanitize_output(stdout) if sanitize else stdout,
        "stderr": sanitize_output(stderr) if sanitize else stderr,
        "status": status_code,
        "success": True if status_code == 0 else False,
    }

    return result_dict