Skip to content

Commit

Permalink
Merge pull request #4728 from lexming/perl-interact-shell
Browse files Browse the repository at this point in the history
do not attach PIPE file handle on STDIN of `run_shell_cmd` unless there are contents for it
  • Loading branch information
boegel authored Dec 23, 2024
2 parents c999fe4 + a5e0937 commit 25a9978
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 25a9978

Please sign in to comment.