def call()

in eng/scripts/helpers.py [0:0]


def call(cmd: str, cwd=root_dir, suppress_failures=False, capture_output=False):
    print("\n============================================================")
    print(f"From {cwd}\n> {cmd}")
    print("============================================================", flush=True)

    start_time = time.time()

    process = subprocess.run(
        cmd,
        cwd=cwd,
        shell=True,
        text=True,
        stdout=subprocess.PIPE if capture_output else None,
        stderr=subprocess.STDOUT if capture_output else None,
    )

    returncode = process.returncode

    if capture_output:
        print(process.stdout.rstrip(), flush=True)

    elapsed_time = time.time() - start_time

    command_failed = returncode != 0 and not suppress_failures

    print("------------------------------------------------------------")
    if command_failed:
        print(f"##[error]Command failed: {cmd}")
    else:
        print(f"End: {cmd}")
    print(f"Exit code {returncode}, Duration: {elapsed_time:.3f}s")
    print("------------------------------------------------------------\n", flush=True)

    if command_failed:
        sys.exit(returncode)

    return process.stdout