mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-07 13:15:00 +00:00
refactor: simplify shell command execution logic
This commit is contained in:
parent
1327c1e893
commit
765ea801b1
1 changed files with 8 additions and 13 deletions
|
@ -25,22 +25,18 @@ def run_cmd(command, verbose=False, error_print=None):
|
||||||
def run_cmd_subprocess(command, verbose=False):
|
def run_cmd_subprocess(command, verbose=False):
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Using run_cmd_subprocess:", command)
|
print("Using run_cmd_subprocess:", command)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
shell = os.environ.get("SHELL", "/bin/sh")
|
||||||
|
PSModulePath = os.environ.get("PSModulePath", "")
|
||||||
# Determine the appropriate shell
|
# Determine the appropriate shell
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows" and "powershell" in PSModulePath.lower():
|
||||||
# Use PowerShell if it's the parent process
|
command = f"powershell -Command {command}"
|
||||||
if "powershell" in os.environ.get("PSModulePath", "").lower():
|
|
||||||
shell = "powershell"
|
|
||||||
command = (
|
|
||||||
f'powershell -ExecutionPolicy Bypass -Command "& {{({command}) | Out-String}}"'
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
shell = "cmd"
|
|
||||||
else:
|
|
||||||
shell = os.environ.get("SHELL", "/bin/sh")
|
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Using shell: {shell}")
|
print("Running command:", command)
|
||||||
|
print("SHELL:", shell)
|
||||||
|
print("PSModulePath:", PSModulePath)
|
||||||
|
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
|
@ -48,7 +44,6 @@ def run_cmd_subprocess(command, verbose=False):
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
text=True,
|
text=True,
|
||||||
shell=True,
|
shell=True,
|
||||||
executable=shell,
|
|
||||||
encoding=sys.stdout.encoding,
|
encoding=sys.stdout.encoding,
|
||||||
errors="replace",
|
errors="replace",
|
||||||
bufsize=1,
|
bufsize=1,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue