Run dashboard Terminal commands through PowerShell on Windows

subprocess.run(..., shell=True) uses cmd.exe on Windows by default,
which doesn't understand PowerShell syntax like $env:VAR or
$env:USERPROFILE - commands using it failed with 'cannot find the
file specified' since cmd took it as a literal filename. Invoke
powershell.exe explicitly on Windows instead; POSIX behavior is
unchanged.
This commit is contained in:
Claude 2026-07-06 04:09:03 +00:00
parent fb3a1979dc
commit 22f8c710dd
1 changed files with 10 additions and 4 deletions

View File

@ -692,10 +692,16 @@ def run_terminal_command(req: TerminalRunRequest):
return {"cwd": _terminal_cwd, "stdout": "", "stderr": "", "returncode": 0, "timed_out": False}
try:
r = subprocess.run(
command, shell=True, cwd=_terminal_cwd,
capture_output=True, text=True, timeout=60,
)
if os.name == "nt":
r = subprocess.run(
["powershell", "-NoProfile", "-NonInteractive", "-Command", command],
cwd=_terminal_cwd, capture_output=True, text=True, timeout=60,
)
else:
r = subprocess.run(
command, shell=True, cwd=_terminal_cwd,
capture_output=True, text=True, timeout=60,
)
append_audit({"action": "terminal_command", "command": command[:200], "cwd": _terminal_cwd})
return {"cwd": _terminal_cwd, "stdout": r.stdout, "stderr": r.stderr, "returncode": r.returncode, "timed_out": False}
except subprocess.TimeoutExpired: