MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / run_cmd

Function run_cmd

monai/utils/misc.py:877–907  ·  view source on GitHub ↗

Run a command by using ``subprocess.run`` with capture_output=True and stderr=subprocess.STDOUT so that the raise exception will have that information. The argument `capture_output` can be set explicitly if desired, but will be overriden with the debug status from the variable. Arg

(cmd_list: list[str], **kwargs: Any)

Source from the content-addressed store, hash-verified

875
876
877def run_cmd(cmd_list: list[str], **kwargs: Any) -> subprocess.CompletedProcess:
878 """
879 Run a command by using ``subprocess.run`` with capture_output=True and stderr=subprocess.STDOUT
880 so that the raise exception will have that information. The argument `capture_output` can be set explicitly
881 if desired, but will be overriden with the debug status from the variable.
882
883 Args:
884 cmd_list: a list of strings describing the command to run.
885 kwargs: keyword arguments supported by the ``subprocess.run`` method.
886
887 Returns:
888 a CompletedProcess instance after the command completes.
889 """
890 debug = MONAIEnvVars.debug()
891 # Always capture output when check=True so that error details are available
892 # in the CalledProcessError exception for debugging subprocess failures.
893 if kwargs.get("check", False):
894 kwargs.setdefault("capture_output", True)
895 else:
896 kwargs["capture_output"] = kwargs.get("capture_output", debug)
897
898 if kwargs.pop("run_cmd_verbose", False):
899 import monai
900
901 monai.apps.utils.get_logger("monai.utils.run_cmd").info(f"{cmd_list}") # type: ignore[attr-defined]
902 try:
903 return subprocess.run(cmd_list, **kwargs)
904 except subprocess.CalledProcessError as e:
905 output = str(e.stdout.decode(errors="replace")) if e.stdout else ""
906 errors = str(e.stderr.decode(errors="replace")) if e.stderr else ""
907 raise RuntimeError(f"subprocess call error {e.returncode}: {errors}, {output}") from e
908
909
910def is_sqrt(num: Sequence[int] | int) -> bool:

Callers 6

_run_cmdMethod · 0.90
_train_algo_in_nniMethod · 0.90
train_single_modelMethod · 0.90
_run_cmd_torchrunFunction · 0.90
_run_cmd_bcprunFunction · 0.90
test_run_cmdMethod · 0.90

Calls 6

debugMethod · 0.80
getMethod · 0.80
popMethod · 0.80
infoMethod · 0.80
runMethod · 0.45
decodeMethod · 0.45

Tested by 1

test_run_cmdMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…