From 3a66bcbfe36cbc6246232f3b1c5b3d2ad121917c Mon Sep 17 00:00:00 2001 From: Harish Date: Thu, 25 Jan 2018 10:58:29 +0530 Subject: [PATCH] process.py: Add subprocess stdin.write() method Add support to provide input with subprocess.Popen's stdin.write method. Optionally flush the input buffer. Signed-off-by: Harish --- avocado/utils/process.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/avocado/utils/process.py b/avocado/utils/process.py index 16bc87e4..e1d733b7 100644 --- a/avocado/utils/process.py +++ b/avocado/utils/process.py @@ -531,6 +531,7 @@ class SubProcess(object): else: stderr = subprocess.PIPE self._popen = subprocess.Popen(cmd, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, shell=self.shell, @@ -701,6 +702,16 @@ class SubProcess(object): self._fill_results(rc) return rc + def stdin_write(self, value, flush=False): + """ + Call the subprocess stdin.write() method for any input to subprocess + Optionally flush the input buffer + """ + self._init_subprocess() + self._popen.stdin.write(value) + if flush: + self._popen.stdin.flush() + def stop(self): """ Stop background subprocess. -- GitLab