support/testing/infra: improve run_cmd_on_host() to show stdout/stderr
When run_cmd_on_host() runs a command that fails, we only get an
exception with no details to debug what happened. Let's improve that
by catching the exception, and printing the command output. This
requires redirecting stderr to stdout (instead of /dev/null) and
asking to get the output in text format.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Julien Olivain <ju.o@free.fr>
(cherry picked from commit 01dc13adfb)
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
This commit is contained in:
committed by
Thomas Perale
parent
838a4e34f0
commit
cd4e06c31a
@@ -59,11 +59,20 @@ def download(dldir, filename):
|
||||
|
||||
def run_cmd_on_host(builddir, cmd):
|
||||
"""Call subprocess.check_output and return the text output."""
|
||||
out = subprocess.check_output(cmd,
|
||||
stderr=open(os.devnull, "w"),
|
||||
cwd=builddir,
|
||||
env={"LANG": "C"},
|
||||
universal_newlines=True)
|
||||
try:
|
||||
out = subprocess.check_output(cmd,
|
||||
cwd=builddir,
|
||||
env={"LANG": "C"},
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
universal_newlines=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Command failed with return code {e.returncode}")
|
||||
print("=== STDOUT/STDERR ===")
|
||||
print(e.output)
|
||||
print("=====================")
|
||||
raise
|
||||
|
||||
return out
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user