Skip to content

Commit

Permalink
Handle no admin process spawn better
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddieAkeroyd committed Dec 19, 2024
1 parent 5c725cb commit 803abef
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions installation_and_upgrade/ibex_install_utils/admin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ def run_command(command: str, parameters: str, expected_return_val: int | None =
lpFile=command,
lpParameters=parameters,
)

win32event.WaitForSingleObject(process_info["hProcess"], 600000)
ret = win32process.GetExitCodeProcess(process_info["hProcess"])
win32api.CloseHandle(process_info["hProcess"])
ret = None
try:
win32event.WaitForSingleObject(process_info["hProcess"], 600000)
ret = win32process.GetExitCodeProcess(process_info["hProcess"])
win32api.CloseHandle(process_info["hProcess"])
except Exception as e:
print(e)
raise IOError("Process not created")

if ret != expected_return_val:
raise IOError(f"Process returned {ret} (expected {expected_return_val})")
Expand Down Expand Up @@ -64,14 +68,15 @@ def run_all(self) -> str:

bat_file += "exit /B 0\r\n"

comspec = os.getenv("COMSPEC", "cmd.exe")
with temp_bat_file(bat_file) as f:
print(
f"Executing bat script as admin. Saved as {f}. Check for an admin prompt. "
f"Log at {log_file.name}."
)
sleep(1) # Wait for file handle to be closed etc
try:
AdminRunner.run_command("cmd", f"/c {f}", expected_return_val=0)
AdminRunner.run_command(f"{comspec}", f"/c {f}", expected_return_val=0)
except IOError as e:
print(f"Error while executing bat script: {e}.")
with open(log_file.name, "r") as logfile:
Expand Down

0 comments on commit 803abef

Please sign in to comment.