MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / check_output

Function check_output

tools/python-3.11.9-amd64/Lib/_bootsubprocess.py:66–97  ·  view source on GitHub ↗
(cmd, **kwargs)

Source from the content-addressed store, hash-verified

64
65# _aix_support used by distutil.util calls subprocess.check_output()
66def check_output(cmd, **kwargs):
67 if kwargs:
68 raise NotImplementedError(repr(kwargs))
69
70 if not _check_cmd(cmd):
71 raise ValueError(f"unsupported command: {cmd!r}")
72
73 tmp_filename = "check_output.tmp"
74 if not isinstance(cmd, str):
75 cmd = " ".join(cmd)
76 cmd = f"{cmd} >{tmp_filename}"
77
78 try:
79 # system() spawns a shell
80 status = os.system(cmd)
81 exitcode = os.waitstatus_to_exitcode(status)
82 if exitcode:
83 raise ValueError(f"Command {cmd!r} returned non-zero "
84 f"exit status {exitcode!r}")
85
86 try:
87 with open(tmp_filename, "rb") as fp:
88 stdout = fp.read()
89 except FileNotFoundError:
90 stdout = b''
91 finally:
92 try:
93 os.unlink(tmp_filename)
94 except OSError:
95 pass
96
97 return stdout

Callers

nothing calls this directly

Calls 6

_check_cmdFunction · 0.85
systemMethod · 0.80
openFunction · 0.70
joinMethod · 0.45
readMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected