mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
utils/misc: add combined output option to check_output
Add an option to combine stderr and stdout into a single stream.
This commit is contained in:
parent
69cd3be96c
commit
d4b0dedc2a
@ -143,7 +143,8 @@ check_output_logger = logging.getLogger('check_output')
|
||||
check_output_lock = threading.Lock()
|
||||
|
||||
|
||||
def check_output(command, timeout=None, ignore=None, inputtext=None, **kwargs):
|
||||
def check_output(command, timeout=None, ignore=None, inputtext=None,
|
||||
combined_output=False, **kwargs):
|
||||
"""This is a version of subprocess.check_output that adds a timeout parameter to kill
|
||||
the subprocess if it does not return within the specified time."""
|
||||
# pylint: disable=too-many-branches
|
||||
@ -165,9 +166,10 @@ def check_output(command, timeout=None, ignore=None, inputtext=None, **kwargs):
|
||||
pass # process may have already terminated.
|
||||
|
||||
with check_output_lock:
|
||||
stderr = subprocess.STDOUT if combined_output else subprocess.PIPE
|
||||
process = subprocess.Popen(command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
stderr=stderr,
|
||||
stdin=subprocess.PIPE,
|
||||
preexec_fn=preexec_function,
|
||||
**kwargs)
|
||||
@ -181,6 +183,7 @@ def check_output(command, timeout=None, ignore=None, inputtext=None, **kwargs):
|
||||
if sys.version_info[0] == 3:
|
||||
# Currently errors=replace is needed as 0x8c throws an error
|
||||
output = output.decode(sys.stdout.encoding, "replace")
|
||||
if error:
|
||||
error = error.decode(sys.stderr.encoding, "replace")
|
||||
finally:
|
||||
if timeout:
|
||||
|
Loading…
x
Reference in New Issue
Block a user