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:
parent
fb3a1979dc
commit
22f8c710dd
14
server.py
14
server.py
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue