From a5e0937321cc066fe793f99e5ecae951dd44d3f6 Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Sun, 22 Dec 2024 23:55:17 +0100 Subject: [PATCH] do not attach PIPE file handle on STDIN of run_shell_cmd unless there are contents to be passed through it --- easybuild/tools/run.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/easybuild/tools/run.py b/easybuild/tools/run.py index 4911ae4e8e..78051c9ff3 100644 --- a/easybuild/tools/run.py +++ b/easybuild/tools/run.py @@ -495,14 +495,15 @@ def to_cmd_str(cmd): else: executable, shell = None, False - stderr = subprocess.PIPE if split_stderr else subprocess.STDOUT + stderr_handle = subprocess.PIPE if split_stderr else subprocess.STDOUT + stdin_handle = subprocess.PIPE if stdin or qa_patterns else None log_msg = f"Running {interactive_msg}shell command '{cmd_str}' in {work_dir}" if thread_id: log_msg += f" (via thread with ID {thread_id})" _log.info(log_msg) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr, stdin=subprocess.PIPE, + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr_handle, stdin=stdin_handle, cwd=work_dir, env=env, shell=shell, executable=executable) # 'input' value fed to subprocess.run must be a byte sequence @@ -515,7 +516,8 @@ def to_cmd_str(cmd): # make stdout, stderr, stdin non-blocking files channels = [proc.stdout, proc.stdin] if split_stderr: - channels += proc.stderr + channels.append(proc.stderr) + for channel in channels: fd = channel.fileno() flags = fcntl.fcntl(fd, fcntl.F_GETFL)