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

Function check_output

tools/python-3.11.9-amd64/Lib/subprocess.py:417–467  ·  view source on GitHub ↗

r"""Run command with arguments and return its output. If the exit code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and output in the output attribute. The arguments are the same as for the P

(*popenargs, timeout=None, **kwargs)

Source from the content-addressed store, hash-verified

415
416
417def check_output(*popenargs, timeout=None, **kwargs):
418 r"""Run command with arguments and return its output.
419
420 If the exit code was non-zero it raises a CalledProcessError. The
421 CalledProcessError object will have the return code in the returncode
422 attribute and output in the output attribute.
423
424 The arguments are the same as for the Popen constructor. Example:
425
426 >>> check_output(["ls", "-l", "/dev/null"])
427 b'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
428
429 The stdout argument is not allowed as it is used internally.
430 To capture standard error in the result, use stderr=STDOUT.
431
432 >>> check_output(["/bin/sh", "-c",
433 ... "ls -l non_existent_file ; exit 0"],
434 ... stderr=STDOUT)
435 b'ls: non_existent_file: No such file or directory\n'
436
437 There is an additional optional argument, "input", allowing you to
438 pass a string to the subprocess's stdin. If you use this argument
439 you may not also use the Popen constructor's "stdin" argument, as
440 it too will be used internally. Example:
441
442 >>> check_output(["sed", "-e", "s/foo/bar/"],
443 ... input=b"when in the course of fooman events\n")
444 b'when in the course of barman events\n'
445
446 By default, all communication is in bytes, and therefore any "input"
447 should be bytes, and the return value will be bytes. If in text mode,
448 any "input" should be a string, and the return value will be a string
449 decoded according to locale encoding, or by "encoding" if set. Text mode
450 is triggered by setting any of text, encoding, errors or universal_newlines.
451 """
452 for kw in ('stdout', 'check'):
453 if kw in kwargs:
454 raise ValueError(f'{kw} argument not allowed, it will be overridden.')
455
456 if 'input' in kwargs and kwargs['input'] is None:
457 # Explicitly passing input=None was previously equivalent to passing an
458 # empty string. That is maintained here for backwards compatibility.
459 if kwargs.get('universal_newlines') or kwargs.get('text') or kwargs.get('encoding') \
460 or kwargs.get('errors'):
461 empty = ''
462 else:
463 empty = b''
464 kwargs['input'] = empty
465
466 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
467 **kwargs).stdout
468
469
470class CompletedProcess(object):

Callers 4

is_cygwingccFunction · 0.90
is_cygwinccFunction · 0.90
quiet_subprocess_runnerFunction · 0.90
getstatusoutputFunction · 0.70

Calls 2

runFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected