Skip to content

Commit c0a1b43

Browse files
authored
Fix subprocess.run() hanging on commands that read stdin (#281)
Commands like `cat > file.py` (without heredoc) block forever waiting for stdin input when executed via `execute()`. This happens because subprocess.run() inherits the parent's stdin by default, which in a server context is a pipe that never sends data. Adding stdin=subprocess.DEVNULL gives these commands an immediate EOF, so they return instantly instead of hanging until the timeout kills them. This is especially important for agent-based workflows where LLMs may generate `cat > file` commands expecting interactive input that will never come.
1 parent 67be423 commit c0a1b43

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/swerex/runtime/local.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ async def execute(self, command: Command) -> CommandResponse:
429429
shell=command.shell,
430430
timeout=command.timeout,
431431
env=command.env,
432+
stdin=subprocess.DEVNULL,
432433
stdout=subprocess.PIPE,
433434
stderr=subprocess.STDOUT if command.merge_output_streams else subprocess.PIPE,
434435
cwd=command.cwd,

0 commit comments

Comments
 (0)