aboutsummaryrefslogtreecommitdiff
path: root/verif/runner/run_command.py
diff options
context:
space:
mode:
Diffstat (limited to 'verif/runner/run_command.py')
-rw-r--r--verif/runner/run_command.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/verif/runner/run_command.py b/verif/runner/run_command.py
index eef5a76..97d9837 100644
--- a/verif/runner/run_command.py
+++ b/verif/runner/run_command.py
@@ -1,5 +1,5 @@
"""Shell command runner function."""
-# Copyright (c) 2020-2022, ARM Limited.
+# Copyright (c) 2020-2024, ARM Limited.
# SPDX-License-Identifier: Apache-2.0
import shlex
import subprocess
@@ -33,18 +33,28 @@ class RunShCommandError(Exception):
def run_sh_command(full_cmd, verbose=False, capture_output=False):
"""Run an external shell command.
- full_cmd: array containing shell command and its arguments
+ full_cmd: string, or array containing shell command and its arguments
verbose: optional flag that enables verbose output
capture_output: optional flag to return captured stdout/stderr
"""
- # Quote the command line for printing
- full_cmd_esc = [shlex.quote(x) for x in full_cmd]
+
+ is_str = True if isinstance(full_cmd, str) else False
+ is_list = True if isinstance(full_cmd, list) else False
+
+ if is_list:
+ # Quote the command line for printing
+ full_cmd_esc = [shlex.quote(x) for x in full_cmd]
if verbose:
- print("### Running {}".format(" ".join(full_cmd_esc)))
+ if is_list:
+ print("### Running {}".format(" ".join(full_cmd_esc)))
+ if is_str:
+ print("### Running {}".format(full_cmd))
if capture_output:
- rc = subprocess.run(full_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ rc = subprocess.run(
+ full_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=is_str
+ )
stdout = rc.stdout.decode("utf-8")
stderr = rc.stderr.decode("utf-8")
if verbose:
@@ -54,8 +64,10 @@ def run_sh_command(full_cmd, verbose=False, capture_output=False):
print(stderr, end="")
else:
stdout, stderr = None, None
- rc = subprocess.run(full_cmd)
+ rc = subprocess.run(full_cmd, shell=is_str)
if rc.returncode != 0:
- raise RunShCommandError(rc.returncode, full_cmd_esc, stderr, stdout)
+ raise RunShCommandError(
+ rc.returncode, full_cmd_esc if is_list else full_cmd, stderr, stdout
+ )
return (stdout, stderr)