feat: implement real-time output display in run_cmd_subprocess

This commit is contained in:
Paul Gauthier (aider) 2024-08-30 08:32:19 -07:00
parent 64b05a9971
commit afa7d02906

View file

@ -18,7 +18,7 @@ def run_cmd(command):
def run_cmd_subprocess(command): def run_cmd_subprocess(command):
try: try:
result = subprocess.run( process = subprocess.Popen(
command, command,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
@ -26,8 +26,17 @@ def run_cmd_subprocess(command):
shell=True, shell=True,
encoding=sys.stdout.encoding, encoding=sys.stdout.encoding,
errors="replace", errors="replace",
bufsize=1,
universal_newlines=True
) )
return result.returncode, result.stdout
output = []
for line in process.stdout:
print(line, end='') # Print the line in real-time
output.append(line) # Store the line for later use
process.wait()
return process.returncode, ''.join(output)
except Exception as e: except Exception as e:
return 1, str(e) return 1, str(e)