From ab9d9c8429487f9a924ecc9bf1ff5bcfa78c2117 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 10 Sep 2024 09:34:58 -0700 Subject: [PATCH] refactor: improve subprocess output handling for real-time display --- aider/run_cmd.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/aider/run_cmd.py b/aider/run_cmd.py index 316d19ae7..e72dbe9c3 100644 --- a/aider/run_cmd.py +++ b/aider/run_cmd.py @@ -50,7 +50,6 @@ def run_cmd_subprocess(command, verbose=False): parent_process = get_windows_parent_process_name() if parent_process == "powershell.exe": command = f"powershell -Command {command}" - # else: Assume cmd.exe or other Windows shell, use the command as-is if verbose: print("Running command:", command) @@ -66,14 +65,17 @@ def run_cmd_subprocess(command, verbose=False): shell=True, encoding=sys.stdout.encoding, errors="replace", - bufsize=1, + bufsize=0, # Set bufsize to 0 for unbuffered output universal_newlines=True, ) output = [] - for line in process.stdout: - print(line, end="") # Print the line in real-time - output.append(line) # Store the line for later use + while True: + chunk = process.stdout.read(1024) # Read in 1KB chunks + if not chunk: + break + print(chunk, end="", flush=True) # Print the chunk in real-time + output.append(chunk) # Store the chunk for later use process.wait() return process.returncode, "".join(output)