Skip to content

Commit 1c7ef31

Browse files
committed
fix: preserve command output on Windows
1 parent a6579c9 commit 1c7ef31

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

aider/run_cmd.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
def run_cmd(command, verbose=False, error_print=None, cwd=None):
1212
try:
13-
if sys.stdin.isatty() and hasattr(pexpect, "spawn") and platform.system() != "Windows":
13+
if (
14+
sys.stdin.isatty()
15+
and hasattr(pexpect, "spawn")
16+
and platform.system() != "Windows"
17+
):
1418
return run_cmd_pexpect(command, verbose, cwd)
1519

1620
return run_cmd_subprocess(command, verbose, cwd)
@@ -47,11 +51,8 @@ def run_cmd_subprocess(command, verbose=False, cwd=None, encoding=sys.stdout.enc
4751
shell = os.environ.get("SHELL", "/bin/sh")
4852
parent_process = None
4953

50-
# Determine the appropriate shell
5154
if platform.system() == "Windows":
5255
parent_process = get_windows_parent_process_name()
53-
if parent_process == "powershell.exe":
54-
command = f"powershell -Command {command}"
5556

5657
if verbose:
5758
print("Running command:", command)
@@ -73,6 +74,7 @@ def run_cmd_subprocess(command, verbose=False, cwd=None, encoding=sys.stdout.enc
7374
)
7475

7576
output = []
77+
assert process.stdout is not None
7678
while True:
7779
chunk = process.stdout.read(1)
7880
if not chunk:
@@ -113,7 +115,9 @@ def output_callback(b):
113115
# Use the shell from SHELL environment variable
114116
if verbose:
115117
print("Running pexpect.spawn with shell:", shell)
116-
child = pexpect.spawn(shell, args=["-i", "-c", command], encoding="utf-8", cwd=cwd)
118+
child = pexpect.spawn(
119+
shell, args=["-i", "-c", command], encoding="utf-8", cwd=cwd
120+
)
117121
else:
118122
# Fall back to spawning the command directly
119123
if verbose:

tests/basic/test_run_cmd.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest # noqa: F401
22

3-
from aider.run_cmd import run_cmd
3+
from aider.run_cmd import run_cmd, run_cmd_subprocess
44

55

66
def test_run_cmd_echo():
@@ -9,3 +9,15 @@ def test_run_cmd_echo():
99

1010
assert exit_code == 0
1111
assert output.strip() == "Hello, World!"
12+
13+
14+
def test_run_cmd_subprocess_preserves_commas_in_powershell(monkeypatch):
15+
monkeypatch.setattr("aider.run_cmd.platform.system", lambda: "Windows")
16+
monkeypatch.setattr(
17+
"aider.run_cmd.get_windows_parent_process_name", lambda: "powershell.exe"
18+
)
19+
20+
exit_code, output = run_cmd_subprocess("echo Hello, World!")
21+
22+
assert exit_code == 0
23+
assert output.strip() == "Hello, World!"

0 commit comments

Comments
 (0)