Skip to content

Commit

Permalink
fix: pass stdin=DEVNULL to Popen to avoid eating stdin from pipes (#4189
Browse files Browse the repository at this point in the history
)

- 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 <[email protected]>

* undo the wrapped lines which is unnecessary

Signed-off-by: Xiangce Liu <[email protected]>
  • Loading branch information
xiangce authored Aug 22, 2024
1 parent 19a7722 commit 995a5f6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions insights/util/subproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 995a5f6

Please sign in to comment.