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

Function run_command

versioneer.py:386–429  ·  view source on GitHub ↗

Call the given command(s).

(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None)

Source from the content-addressed store, hash-verified

384
385
386def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
387 """Call the given command(s)."""
388 assert isinstance(commands, list)
389 process = None
390
391 popen_kwargs = {}
392 if sys.platform == "win32":
393 # This hides the console window if pythonw.exe is used
394 startupinfo = subprocess.STARTUPINFO()
395 startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
396 popen_kwargs["startupinfo"] = startupinfo
397
398 for command in commands:
399 try:
400 dispcmd = str([command] + args)
401 # remember shell=False, so use git.cmd on windows, not just git
402 process = subprocess.Popen(
403 [command] + args,
404 cwd=cwd,
405 env=env,
406 stdout=subprocess.PIPE,
407 stderr=(subprocess.PIPE if hide_stderr else None),
408 **popen_kwargs,
409 )
410 break
411 except OSError:
412 e = sys.exc_info()[1]
413 if e.errno == errno.ENOENT:
414 continue
415 if verbose:
416 print("unable to run %s" % dispcmd)
417 print(e)
418 return None, None
419 else:
420 if verbose:
421 print("unable to find command, tried %s" % (commands,))
422 return None, None
423 stdout = process.communicate()[0].strip().decode()
424 if process.returncode != 0:
425 if verbose:
426 print("unable to run %s (error)" % dispcmd)
427 print("stdout was %s" % stdout)
428 return None, process.returncode
429 return stdout, process.returncode
430
431
432LONG_VERSION_PY[

Callers 1

do_vcs_installFunction · 0.70

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…