aboutsummaryrefslogtreecommitdiff
path: root/test/py/multiplexed_log.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-10-23 17:25:57 -0600
committerSimon Glass <sjg@chromium.org>2021-11-28 16:51:51 -0700
commit15156c95e9710447cc66f4b18009220bc4098d4e (patch)
treebb5072d828bff1b0d189e0e4156e2cfbb5e95e2e /test/py/multiplexed_log.py
parentc700f109a312d0c14b5409765013af4b7335d879 (diff)
test/py: Allow passing input to a program
When running a program on the host, allow input to be passed in as stdin. This is needed for running sfdisk, for example. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/py/multiplexed_log.py')
-rw-r--r--test/py/multiplexed_log.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 545a774302..9325fae46d 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -109,7 +109,7 @@ class RunAndLog(object):
"""Clean up any resources managed by this object."""
pass
- def run(self, cmd, cwd=None, ignore_errors=False):
+ def run(self, cmd, cwd=None, ignore_errors=False, stdin=None):
"""Run a command as a sub-process, and log the results.
The output is available at self.output which can be useful if there is
@@ -123,6 +123,7 @@ class RunAndLog(object):
function will simply return if the command cannot be executed
or exits with an error code, otherwise an exception will be
raised if such problems occur.
+ stdin: Input string to pass to the command as stdin (or None)
Returns:
The output as a string.
@@ -135,8 +136,9 @@ class RunAndLog(object):
try:
p = subprocess.Popen(cmd, cwd=cwd,
- stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- (stdout, stderr) = p.communicate()
+ stdin=subprocess.PIPE if stdin else None,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ (stdout, stderr) = p.communicate(input=stdin)
if stdout is not None:
stdout = stdout.decode('utf-8')
if stderr is not None: