Skip to content

Commit 803abef

Browse files
Handle no admin process spawn better
1 parent 5c725cb commit 803abef

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

installation_and_upgrade/ibex_install_utils/admin_runner.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ def run_command(command: str, parameters: str, expected_return_val: int | None =
2727
lpFile=command,
2828
lpParameters=parameters,
2929
)
30-
31-
win32event.WaitForSingleObject(process_info["hProcess"], 600000)
32-
ret = win32process.GetExitCodeProcess(process_info["hProcess"])
33-
win32api.CloseHandle(process_info["hProcess"])
30+
ret = None
31+
try:
32+
win32event.WaitForSingleObject(process_info["hProcess"], 600000)
33+
ret = win32process.GetExitCodeProcess(process_info["hProcess"])
34+
win32api.CloseHandle(process_info["hProcess"])
35+
except Exception as e:
36+
print(e)
37+
raise IOError("Process not created")
3438

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

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

71+
comspec = os.getenv("COMSPEC", "cmd.exe")
6772
with temp_bat_file(bat_file) as f:
6873
print(
6974
f"Executing bat script as admin. Saved as {f}. Check for an admin prompt. "
7075
f"Log at {log_file.name}."
7176
)
7277
sleep(1) # Wait for file handle to be closed etc
7378
try:
74-
AdminRunner.run_command("cmd", f"/c {f}", expected_return_val=0)
79+
AdminRunner.run_command(f"{comspec}", f"/c {f}", expected_return_val=0)
7580
except IOError as e:
7681
print(f"Error while executing bat script: {e}.")
7782
with open(log_file.name, "r") as logfile:

0 commit comments

Comments
 (0)