From 995a5f62bc7e892a0a6a2bf786df9352956d32e5 Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Thu, 22 Aug 2024 14:06:04 +0800 Subject: [PATCH] fix: pass stdin=DEVNULL to Popen to avoid eating stdin from pipes (#4189) - For the first cmd to run in subprocess.call, specified "stdin=subprocess.DEVNULL" to avoid it from eating the stdin behind it - also fix: #4187 in the base call Signed-off-by: Xiangce Liu * undo the wrapped lines which is unnecessary Signed-off-by: Xiangce Liu --- insights/util/subproc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/insights/util/subproc.py b/insights/util/subproc.py index 547ff0e5ca..d3cd46c4c2 100644 --- a/insights/util/subproc.py +++ b/insights/util/subproc.py @@ -10,6 +10,11 @@ from insights.core.exceptions import CalledProcessError from insights.util import which +try: + from subprocess import DEVNULL +except: + DEVNULL = open(os.devnull, 'w') + log = logging.getLogger(__name__) @@ -57,9 +62,9 @@ def __init__(self, *cmds, **kwargs): def _build_pipes(self, out_stream=PIPE): log.debug("Executing: %s" % str(self.cmds)) if len(self.cmds) == 1: - return Popen(self.cmds[0], bufsize=self.bufsize, stderr=STDOUT, stdout=out_stream, env=self.env) + return Popen(self.cmds[0], bufsize=self.bufsize, stdin=DEVNULL, stderr=STDOUT, stdout=out_stream, env=self.env) - stdout = Popen(self.cmds[0], bufsize=self.bufsize, stderr=STDOUT, stdout=PIPE, env=self.env).stdout + stdout = Popen(self.cmds[0], bufsize=self.bufsize, stdin=DEVNULL, stderr=STDOUT, stdout=PIPE, env=self.env).stdout last = len(self.cmds) - 2 for i, arg in enumerate(self.cmds[1:]): if i < last: