Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle no admin process spawn better #215

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading