mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 10:14:59 +00:00
aider: Modify run_cmd
method to capture both stdout and stderr together using subprocess.Popen
.
# Aider chat conversation: USER: can `check_output` intermingle stdout and stdin like they would be in a terminal? ASSISTANT: The `subprocess.check_output` function captures the output of the command and returns it as a string. It does not intermingle stdout and stderr like they would be in a terminal. If you need to capture both stdout and stderr together, you can use `subprocess.Popen` with `stdout=subprocess.PIPE` and `stderr=subprocess.STDOUT`. Would you like me to modify the `run_cmd` method to use `subprocess.Popen` to capture both stdout and stderr together? USER: yes ASSISTANT: Here are the changes to modify the `run_cmd` method to use `subprocess.Popen` to capture both stdout and stderr together: aider/linter.py ```python <<<<<<< SEARCH try: subprocess.check_output(cmd, cwd=self.root).decode() return # zero exit status except subprocess.CalledProcessError as err: errors = err.output.decode() # non-zero exit status ======= process = subprocess.Popen(cmd, cwd=self.root, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, _ = process.communicate() errors = stdout.decode() if process.returncode == 0: return # zero exit status >>>>>>> REPLACE ``` This change ensures that both stdout and stderr are captured together, similar to how they would be intermingled in a terminal.
This commit is contained in:
parent
8a2ce8ec0e
commit
ee2e633380
1 changed files with 6 additions and 4 deletions
|
@ -38,11 +38,13 @@ class Linter:
|
|||
cmd += " " + rel_fname
|
||||
cmd = cmd.split()
|
||||
|
||||
try:
|
||||
subprocess.check_output(cmd, cwd=self.root).decode()
|
||||
process = subprocess.Popen(
|
||||
cmd, cwd=self.root, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
stdout, _ = process.communicate()
|
||||
errors = stdout.decode()
|
||||
if process.returncode == 0:
|
||||
return # zero exit status
|
||||
except subprocess.CalledProcessError as err:
|
||||
errors = err.output.decode() # non-zero exit status
|
||||
|
||||
cmd = " ".join(cmd)
|
||||
res = f"# Running: {cmd}\n\n"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue