fixes and possible wip gui_2/theme_2 for multi-viewport support
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import subprocess
|
||||
import shlex
|
||||
import subprocess, shutil
|
||||
from pathlib import Path
|
||||
|
||||
TIMEOUT_SECONDS = 60
|
||||
@@ -10,27 +9,20 @@ def run_powershell(script: str, base_dir: str) -> str:
|
||||
Returns a string combining stdout, stderr, and exit code.
|
||||
Raises nothing - all errors are captured into the return string.
|
||||
"""
|
||||
# Prepend Set-Location so the AI doesn't need to worry about cwd
|
||||
full_script = f"Set-Location -LiteralPath '{base_dir}'\n{script}"
|
||||
|
||||
# Try common executable names
|
||||
exe = next((x for x in ["powershell.exe", "pwsh.exe", "powershell", "pwsh"] if shutil.which(x)), None)
|
||||
if not exe: return "ERROR: Neither powershell nor pwsh found in PATH"
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["powershell", "-NoProfile", "-NonInteractive", "-Command", full_script],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=TIMEOUT_SECONDS,
|
||||
cwd=base_dir
|
||||
r = subprocess.run(
|
||||
[exe, "-NoProfile", "-NonInteractive", "-Command", full_script],
|
||||
capture_output=True, text=True, timeout=TIMEOUT_SECONDS, cwd=base_dir
|
||||
)
|
||||
parts = []
|
||||
if result.stdout.strip():
|
||||
parts.append(f"STDOUT:\n{result.stdout.strip()}")
|
||||
if result.stderr.strip():
|
||||
parts.append(f"STDERR:\n{result.stderr.strip()}")
|
||||
parts.append(f"EXIT CODE: {result.returncode}")
|
||||
return "\n".join(parts) if parts else f"EXIT CODE: {result.returncode}"
|
||||
except subprocess.TimeoutExpired:
|
||||
return f"ERROR: command timed out after {TIMEOUT_SECONDS}s"
|
||||
except FileNotFoundError:
|
||||
return "ERROR: powershell executable not found"
|
||||
except Exception as e:
|
||||
return f"ERROR: {e}"
|
||||
if r.stdout.strip(): parts.append(f"STDOUT:\n{r.stdout.strip()}")
|
||||
if r.stderr.strip(): parts.append(f"STDERR:\n{r.stderr.strip()}")
|
||||
parts.append(f"EXIT CODE: {r.returncode}")
|
||||
return "\n".join(parts)
|
||||
except subprocess.TimeoutExpired: return f"ERROR: timed out after {TIMEOUT_SECONDS}s"
|
||||
except Exception as e: return f"ERROR: {e}"
|
||||
|
||||
Reference in New Issue
Block a user